Board index » delphi » TQuery and SQL's OUTER JOINS

TQuery and SQL's OUTER JOINS

I have been trying to use an outer join SQL command in a TQuery component to
join 3 tables.
I am not very familiar with SQL syntax and I am not sure if it can be done.
The only resource I have on SQL is the BORLAND's Local Interbase Server user
guide
where it says that joins can be done on two or more tables but it doesn't say
if this applies to outer joins.

Example (this doesn't work):
SELECT a.*, b.*, c.*
FROM table1 a OUTER JOIN table2 b OUTER JOIN table3 c
ON a.no = b.no
AND b.no = c.no
AND b.no2 = c.no2

If anyone knows how this can be done please get back to me.

MARCEL

 

Re:TQuery and SQL's OUTER JOINS


In article <201095.2148393761...@frontier.canrem.com>
           msvari...@frontier.canrem.com "Marcel Svaricek" writes:

Quote
> I have been trying to use an outer join SQL command in a TQuery component to
> join 3 tables.
> I am not very familiar with SQL syntax and I am not sure if it can be done.
> The only resource I have on SQL is the BORLAND's Local Interbase Server user
> guide
> where it says that joins can be done on two or more tables but it doesn't say
> if this applies to outer joins.

> Example (this doesn't work):
> SELECT a.*, b.*, c.*
> FROM table1 a OUTER JOIN table2 b OUTER JOIN table3 c
> ON a.no = b.no
> AND b.no = c.no
> AND b.no2 = c.no2

> If anyone knows how this can be done please get back to me.

Without actually trying it I suspect the syntax should be

SELECT * FROM table1, table2, table3,
table1 LEFT OUTER JOIN table2 ON table1.no = table2.no,
table1 RIGHT OUTER JOIN table3 ON table1.no = table3.no

The commas at the end of each line are required (I think).

The SQL reference on using Local SQL (as opposed to ISQL) is in Appendix C
of the Database Application Developer's Guide.

--
 Richard Linsley Hood | Poole, Dorset UK | email: richar...@dakal.demon.co.uk
 "Programming is mirroring the world, inside a computer"   Larry O'Brien 1991

Re:TQuery and SQL's OUTER JOINS


msvari...@frontier.canrem.com (Marcel Svaricek)  wrote

Quote
> I have been trying to use an outer join SQL command in a TQuery component to
> join 3 tables.
> The only resource I have on SQL is the BORLAND's Local Interbase Server user
> guide
> where it says that joins can be done on two or more tables but it doesn't
> say if this applies to outer joins.
> If anyone knows how this can be done please get back to me.

Hi Marcel,

at least with two tables I did it succesfully. Look at my sample:

SELECT Section.etno, Spares.pg, Spares.pu, Spares.german
FROM Section s  LEFT OUTER JOIN Spares p ON s.etno=p.etno
WHERE section = :section;

Best regards

Michael
--

Michael Suedkamp                                      m...@suedkm.franken.de

Other Threads