Reputation: 5651
Suppose I have have 2 tables:
USER(uid, uname);
ITEM(iid, description);
TRANSACTION(buyer, seller, item);
transaction.buyer
and transaction.seller
references user.uid
.
transaction.item
references item.iid
How can I query the name of the buyer and seller of a transaction?
Upvotes: 1
Views: 58
Reputation: 1269643
You need two joins:
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
Upvotes: 3