我在下面的查询中做错了什么
Error Message : You can't specify target table 'cp_asseteventinquiry' for update in FROM clause
查询:
UPDATE cp_asseteventinquiry
SET Due_Date= curdate()
WHERE TopLevelAsset_Num =
(
SELECT Distinct(TopLevelAsset_Num) FROM cp_asseteventinquiry
WHERE cp_asseteventinquiry.History='NO'
AND NOT EXISTS(SELECT Scheduled_Date FROM flightlogs
WHERE flightlogs.Asset=cp_asseteventinquiry.TopLevelAsset_Num
AND flightlogs.Scheduled_Date=date_format (curdate(), '%m/%d/%Y'))
);
答案 0 :(得分:0)
用这样的SELECT
包装您的内部查询:
UPDATE cp_asseteventinquiry
SET Due_Date= curdate()
WHERE TopLevelAsset_Num = (
SELECT *
FROM (
SELECT Distinct(TopLevelAsset_Num)
FROM cp_asseteventinquiry
WHERE cp_asseteventinquiry.History='NO'
AND NOT EXISTS( SELECT Scheduled_Date
FROM flightlogs
WHERE flightlogs.Asset=cp_asseteventinquiry.TopLevelAsset_Num
AND flightlogs.Scheduled_Date=date_format (curdate(), '%m/%d/%Y')
)
) AS t)