2009. május 1., péntek

How to join multiple tables


Problem/Question/Abstract:

I am trying to connect a table in Delphi 3 (using Paradox) to receive data from multiple tables. Up till now, I thought using LEFT OUTER JOIN would do the trick, unfortunately, as soon as I hook up the third table, no data is send to the grid. The join has to be in a way of lookup.

Answer:

If your tables have the same struct (or you can force the same structure via SELECT) you can use UNION:

SELECT * FROM Table1
UNION
SELECT * FROM Table2

If your tables have different structs, try FULL OUTER JOIN instead of LEFT following from localsql.hlp:

SELECT * FROM customer C
FULL OUTER JOIN orders O
on(C.custno = O.custno)
FULL OUTER JOIN items I
on(O.orderno = I.orderno)

Nincsenek megjegyzések:

Megjegyzés küldése