views:

19

answers:

1

I have 2 unlike tables and a large set of subqueries that have a key for each of those two tables. I need to join the two tables to each subquery.

Table 1
Table1ID

Table 2
Table2ID

Subqueries
Table1ID
Table2ID

Is there any way to join everything together?

I have tried something similar to

SELECT Table1.Table1ID, Table2.Table2ID
FROM Table1, Table2
LEFT JOIN (SELECT Table1ID, Table2ID FROM ....) q1 ON Table1.Table1ID = q1.Table1ID AND Table2.Table2ID = q1.Table2ID
...
+2  A: 

This following query will select all fields from a join of all three tables on the respective table IDs:

SELECT *
FROM Table1 t1
  INNER JOIN Subqueries s
    ON t1.Tabl1Id = s.Table1Id
  INNER JOIN Table2 t2
    ON s.Tabl2Id = ts.Table2Id

If you need absolutely all records from both Table1 and Table2, whether they are joined via the Subqueries table, then you can change the join to FULL OUTER:

SELECT *
FROM Table1 t1
  FULL OUTER JOIN Subqueries s
    ON t1.Tabl1Id = s.Table1Id
  FULL OUTER JOIN Table2 t2
    ON s.Tabl2Id = ts.Table2Id
Oded
+ one for getting rid of the implied syntax.
HLGEM