2013-07-03 71 views
0

我有2分表加入並顯示從一和表2列由另一個表

列內TABLE_A指:數據,ID_A,ID_B,狀態內

enter image description here

列表-B :id,用戶名

enter image description here

我想顯示從內TABLE_A(ID_A & ID_B)從列表-B參考的用戶名,使別名ID_A爲USER_1和ID_B作爲User_2

我一直與INNER JOIN,但它仍然讓我迷惑

回答

1

你可以試試這個...

SELECT a.username as User_1, b.username as User_2 FROM 
table_A t 
JOIN table_B b on b.id = t.id_B 
JOIN table_B a ON a.id = t.id_A 
相關問題