正在尝试删除由单个语句中的子select生成的id列表。这个是可能的吗?我一直在尝试以下几种方法:
编辑更正的查询
DELETE from store
WHERE id in ( SELECT store.id
FROM storeInfo
JOIN store ON storeInfo.store_id = store.id
WHERE storeInfo.type = 17 )但这是不正确的语法...不确定如何正确地构建它。
发布于 2012-11-21 03:58:23
DELETE store
FROM store
JOIN storeInfo
ON storeInfo.store_id = store.id
WHERE storeInfo.type = 17发布于 2012-11-21 04:00:14
在输入错误更新问题后-您不需要在子查询中使用JOIN。您可以只从IN()子查询返回storeInfo.store_id。
DELETE FROM `store` WHERE `id` IN (SELECT `store_id` FROM `storeInfo` WHERE `type` = 17)MySQL不允许您在子查询中使用表store,然后删除其中的行。但是,您可以使用storeInfo,因为它直接与store_id联接。
如果需要从这两个表中删除(例如,如果storeInfo中的行在其父级从store中删除时变为孤立行),请改用JOIN语法:
DELETE
/* Syntax to delete rows from both tables */
store, storeInfo
FROM
store JOIN storeInfo ON store.id = storeInfo.store_id
WHERE storeInfo.type = 17有关完整的详细信息,请查看MySQL DELETE syntax reference。
发布于 2012-11-21 04:07:34
您可以直接连接到delete中
delete store from store
JOIN storeInfo ON storeInfo.store_id = store.id
WHERE store.type = 17;https://stackoverflow.com/questions/13481061
复制相似问题