tags:

views:

32

answers:

1

I'm a bit confused on this. I have a data table structured like this:

Table: Data

DataID    Val
1         Value 1
2         Value 2
3         Value 3
4         Value 4

Then I have another table structured like this:

Table: Table1

Col1    Col2
1       2
3       4
4       3
2       1

Both columns from Table1 point to the data in the data table. How can I get this data to show in a query? For example, a query to return this:

Query: Query1

Column1    Column2
Value 1    Value 2
Value 3    Value 4
Value 4    Value 3
Value 2    Value 1

I'm familiar enough with SQL to do a join with one column, but lost beyond that. Any help is appreciated. Sample sql or a link to something to read. Thanks!

PS: This is in sqlite

+3  A: 

You can join the same table twice:

Select
  d1.val As column1,
  d2.val As column2
From table1 t
Join data d1 On ( d1.dataId = t.col1 )
Join data d2 On ( d2.dataId = t.col2 )
Peter Lang
+1 Right, a double join is what he's asking for
Andomar
Thanks it works great. I wasn't aware you could specify a join without using inner, left, or right. I really need to read a book on this!
dmaruca
`JOIN` is the same as `INNER JOIN`, while `LEFT JOIN` is the same as `LEFT OUTER JOIN`.
Peter Lang