mysql 一张表的多个字段关联另外一张表

时间:2022-04-19 05:14:43
SELECT
vtiger_orderitem.orderid,
(
SELECT
vtiger_users.last_name
FROM
vtiger_users
WHERE
vtiger_orderitem.signatory = vtiger_users.id
) AS signatory,
(
SELECT
vtiger_users.last_name
FROM
vtiger_users
WHERE
vtiger_orderitem.servicer = vtiger_users.id
) AS servicer
FROM
vtiger_orderitem
SELECT
n.orderid,
m.last_name,
q.last_name
FROM
vtiger_orderitem n
LEFT JOIN vtiger_users m ON n.signatory = m.id
LEFT JOIN vtiger_users q ON n.servicer = q.id