我的tbltransfer
包含location
和eq_id
。我想更改location
中tblequipments
的值location
tbltransfer
,其中eq_id
tblequipments
等于eq_id
tbltransfer
中的UPDATE tblequipments
SET LocationName = (
SELECT t.Location from tbltransfer as t
join tblequipments as e on t.eq_ID = e.eq_ID
WHERE t.transactionID=%s
)
。这是我提出的查询:
{{1}}
答案 0 :(得分:1)
mysql将为update语句中的每一行运行子查询。最好在这里使用join:
UPDATE
tblequipments,
tbltransfer
SET
tblequipments.location = tbltransfer.location
WHERE
tblequipments.eq_id = tbltransfer.eq_id
AND
tbltransfer.transactionID = %s
答案 1 :(得分:1)
UPDATE tblequipments
INNER JOIN tbltransfer ON tblequipments.eq_ID = tbltransfer.eq_ID
SET tblequipments.LocationName=tbltransfer.Location
WHERE tbltransfer.transactionID=%s