假设我有2个表:
USER(uid, uname);
ITEM(iid, description);
TRANSACTION(buyer, seller, item);
transaction.buyer
和transaction.seller
引用user.uid
。
transaction.item
引用item.iid
如何查询交易的买方和卖方的名称?
答案 0 :(得分:3)
您需要两个联接:
select t.*, b.uname as buyerName, s.uname as sellerName
from transaction t join
user b
on t.buyer = b.uid join
user s
on t.seller = s.uid