Mysql query to Delete records after select..? [duplicate]

北城以北 提交于 2020-01-15 20:13:52

问题


after selecting records i want to delete that records..i tried following query - (after removing ,MAX(value) but its showing- You can't specify target table 'test' for update in FROM clause

DELETE FROM test WHERE ext_no IN 
(
SELECT   ext_no, MAX(value)
FROM     test
GROUP BY ext_no
HAVING   COUNT(*) > 2 AND 
         COUNT(*) = COUNT(CASE value WHEN 0 THEN 1 END)
);

回答1:


You can try below - you need to use subquery for inner select statement

DELETE FROM test WHERE ext_no IN 
(
select ext_no from
(
SELECT   ext_no, MAX(value)
FROM     test
GROUP BY ext_no
HAVING   COUNT(*) > 2 AND 
         COUNT(*) = COUNT(CASE value WHEN 0 THEN 1 END)
)t)


来源:https://stackoverflow.com/questions/53370339/mysql-query-to-delete-records-after-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!