Forums.ATC.no

Teknisk => Generelt teknisk => Emne startet av: ATC på 27. ſeptember 2008, 18:24 pm

Tittel: SQL: Joining the same table twice (or more)
Skrevet av: ATC27. ſeptember 2008, 18:24 pm
In table A, "A.foo" and "A.bar" both refer to records in table B. How to join both in a single SQL statement?
Tittel: [Solved] SQL: Joining the same table twice (or more)
Skrevet av: ATC27. ſeptember 2008, 18:24 pm
Use JOIN..AS like this:

SELECT A.*, fooB.*, barB.*
FROM A
LEFT JOIN B AS fooB ON (A.foo = fooB.id)
LEFT JOIN B AS barB ON (A.bar = barB.id)