MySQL Forums
Forum List  »  Newbie

Multi LEFT Join
Posted by: Karthikeyan Kuppusamy
Date: May 28, 2014 11:23AM

Hi, need some urgent help please.

I got a master table t1, reference tables t2, t3 as shown below.

t1
----------------------------------------
ID Name city_code country_code


t2
---------------------------------------
city_code city_name


t3
---------------------------------------
country_code country_name


I'm querying all records in t1, but need to match it with t2 and t3. the issue is not all city_codes are present in t2 and not all country_codes are present t3.

so, when I query t1, I want all the records in t1 to appear but with city_name and country_name where available. in other cases it can be null.


i tried the below query but not giving the results. it is bringing more records than in t1 !


select ID,Name,city_code,country_code,city_name,country_name
from t1
LEFT JOIN t2 ON t1.city_code = t2.city_code
LEFT JOIN t3 ON t1.country_code = t3.country_code


Please help!


thanks

Options: ReplyQuote


Subject
Written By
Posted
Multi LEFT Join
May 28, 2014 11:23AM
May 30, 2014 12:09PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.