我试图删除项items
表。如果它存在,也来自saves
表。
这是错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'i LEFT JOIN saves s ON i.id = s.item_id
DELETE FROM items i
LEFT JOIN saves s
ON i.id = s.item_id
WHERE i.id = ? AND s.item_id = ?
AND
NOT EXISTS (SELECT id FROM pending_wins WHERE item_id = ?)
AND
NOT EXISTS (SELECT id FROM bids WHERE item_id = ?)
答案 0 :(得分:0)
如果您想从单个表中删除,请说items
试试这个::
DELETE i FROM items i
LEFT JOIN saves s
ON i.id = s.item_id
WHERE i.id = ? AND s.item_id = ?
AND
NOT EXISTS (SELECT id FROM pending_wins WHERE item_id = ?)
AND
NOT EXISTS (SELECT id FROM bids WHERE item_id = ?)
如果要从两个表中删除记录,请尝试以下::
DELETE i, s FROM items i
LEFT JOIN saves s
ON i.id = s.item_id
WHERE i.id = ? AND s.item_id = ?
AND
NOT EXISTS (SELECT id FROM pending_wins WHERE item_id = ?)
AND
NOT EXISTS (SELECT id FROM bids WHERE item_id = ?)
答案 1 :(得分:0)
DELETE i, s
FROM items i
LEFT JOIN saves s
ON i.id = s.item_id
WHERE s.item_id = ?
AND
NOT EXISTS (SELECT id FROM pending_wins WHERE item_id = ?)
AND
NOT EXISTS (SELECT id FROM bids WHERE item_id = ?)
答案 2 :(得分:0)
使用以下查询删除表i中的数据:
DELETE i FROM items i
LEFT JOIN saves s
ON i.id = s.item_id
WHERE i.id = ? AND s.item_id = ?
AND
NOT EXISTS (SELECT id FROM pending_wins WHERE item_id = ?)
AND
NOT EXISTS (SELECT id FROM bids WHERE item_id = ?)
答案 3 :(得分:0)
您只需在查询中i
之前添加FROM
DELETE i FROM items i
LEFT JOIN saves s
ON i.id = s.item_id
WHERE i.id = ? AND s.item_id = ?
AND
NOT EXISTS (SELECT id FROM pending_wins WHERE item_id = ?)
AND
NOT EXISTS (SELECT id FROM bids WHERE item_id = ?)