I am looking for a way to perform multiple joins from one source table to more than one table. Similar to the following:
SELECT a.NAME, b.address, c.phone
FROM tblname a
LEFT JOIN tbladdress b ON a.nid = b.nid
I also want to perform a left join on the Telephone table tblPhone
at the same time:
tblname a left join tblPhone c on a.PID = c.PID
Try as I might I can't see how to put this into one query.
SQL LEFT JOIN examples Each location belongs to one and only one country while each country can have zero or more locations. The relationship between the countries and locations tables is one-to-many.
Here when it comes to Left Join in SQL it only returns all the records or tuples or rows from left table and only those records matching from the right table. Syntax For Left Join: SELECT column names FROM table1 LEFT JOIN table2 ON table1.
Yes, indeed! You can use multiple LEFT JOINs in one query if needed for your analysis.
Here's a better formulation without changing anything. It moves the LEFT JOINs into the SELECT part and avoids the GROUP BY . Show activity on this post. Note that in your SELECT clause you should either use values that are grouped by (or functionally dependent on them), or use some aggregation.
You can simply repeat your JOIN
clauses as many times as is needed, e.g.:
SELECT a.NAME
,b.address
,c.phone
FROM tblname a
LEFT JOIN tbladdress b ON a.nid = b.nid
LEFT JOIN tblPhone c ON a.PID = c.PID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With