2013-06-22 63 views
0

表1: -請幫我在寫我的SQL查詢該

name | location | Area | Region | Country 
----------------------------------------- 
abc 8   6  9  12 

表2: -

lid | lname | aid | rid | cid 
def 8  6  9 12 

表3: -

aid | aname | rid | cid 
6  ghi  9  12 

表4: -

rid | rname | cid 
9  jkl  12 

表5: -

cid | cname 
12  mno 

我怎樣才能在mysql中加入這5個表和retrive 「ABC,DEF,GHI,JKL,MNO」;

回答

0

我希望這會爲你工作。

SELECT table1.name, table2.lname ,table3.aname,table4.rname,table5.cname 
FROM table1 
WHERE 
LEFT JOIN table2 ON table2.lid = table1.location 
LEFT JOIN table3 ON table3.aid = table1.area 
LEFT JOIN table4 ON table4.rid = table1.region 
LEFT JOIN table5 ON table5.cid = table1.country