这是两个表“成本”和“联系人”。所有卖家和买家的名字都在“联系人”表中。通过以下查询,我检索每个项目的卖家和买家的 ID,但我想从“联系人”表中获取他们的姓名
SELECT
costs.id as ID,
costs.idContactPayedBy,
costs.idContactPayedTo
FROM costs
WHERE
costs.idbuilding=286
但我想从联系人表中获取卖家和买家的姓名
SELECT
costs.id as ID,
contacts.lastname as seller,
contacts.lastname as buyer
FROM costs , contacts
WHERE
costs.idbuilding=286
and costs.idContactPayedBy = contacts.id
and costs.idContactPayedTo = contacts.id
所以想要的结果是这样的
ID Seller Buyer
21 jackson Brown
29 Bush wilson