「コスト」と「連絡先」の 2 つのテーブルがあります。すべての売り手と買い手の名前は「連絡先」テーブルにあります。次のクエリでは、各アイテムの売り手と買い手の 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