2014-04-01 45 views
0

2個表table1和表2;要求是,如果我在添加FROM語句和AND,以圖列people2表1中兩列從表2如何連接兩個表並映射三列

SELECT , t2.people_names, t2.peoples_names 
FROM (table1 t1 JOIN table2 t2 ON t2.people_ids=t1.people1) 

地圖,我得到一個錯誤。

FROM (table1 t1 JOIN table2 t2 ON t2.people_ids=t1.people1 AND 
    t2.people_ids=t1.people2)​ 

回答

1

您必須加入people_names表兩次。

SELECT t1.people1, tnames1.peoples_names, t1.people2, tnames2.peoples_names 
FROM table1 t1 JOIN table2 tnames1 ON tnames1.people_ids = t1.people1 
       JOIN table2 tnames2 ON tnames2.people_ids = t1.people2 
+0

謝謝。那真的有用! – user3484573

+0

不客氣,歡迎來到StackOverflow。如果這很有用,請考慮將此答案標記爲已接受:) – Aioros