**Friends Table**
-------------------------
id seller_id buyer_id
-------------------------
1 101 102
2 102 104
3 103 101
4 104 101
**Name Table**
--------------
id name_id
--------------
101 Robin
102 Goblin
103 Ork
104 Wizard
我只想让Friends表显示Name而不是name_id和friend_id。 我知道这很简单,但我找不到合适的词来为它辩护。请帮忙..
答案 0 :(得分:1)
select f.id,n.name_id as "seller_id",nb.name_id as "buyer_id"
from [Friends Table] f
join [Name Table] n on n.seller_id=f.id
join [Name Table] nb on nb.buyer_id=f.id
答案 1 :(得分:1)
这可能会对你有帮助。
SELECT F.friend_id, F.id N.name_id FROM Friends_Table F INNER JOIN Name_Table N ON F.id= N.id
答案 2 :(得分:1)
您可以执行两次JOIN
来实现这一目标:
SELECT
f.id
, n1.name_id As seller
, n2.name_id As buyer
FROM Friends f
INNER JOIN Name n1 ON n1.id = f.seller_id
INNER JOIN Name n2 ON n2.id = f.buyer_id
答案 3 :(得分:0)
也许这就是你要找的东西?
select n.name_id
from Friends as f
join Name as n
on f.id = n.id
group by n.name_id