Multiple-table DELETE LIMIT

房东的猫 提交于 2019-12-24 10:37:33

问题


I'm trying to run following query but it throws an error.

DELETE b 
FROM parim_lang a 
JOIN parim_lang b 
    ON b.lang_hash = a.lang_hash 
    AND b.lang_language = SUBSTRING(a.lang_google_translation, LOCATE('-', a.lang_google_translation) + 1)
WHERE a.lang_google_translation REGEXP '^[a-z]+-[a-z]+'
LIMIT 20

Without limit this query works..

Error looks like this:

SQL Error (1064): 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 'LIMIT 20' at line 7

Found this:

For the multiple-table syntax, DELETE deletes from each tbl_name the rows that satisfy the conditions. In this case, ORDER BY and LIMIT cannot be used.

I there any workarounds for this?


回答1:


Try :

DELETE
FROM parim_lang a
WHERE a.lang_hash IN (
SELECT a.lang_hash 
FROM parim_lang a
JOIN parim_lang b 
    ON b.lang_hash = a.lang_hash 
    AND b.lang_language = SUBSTRING(a.lang_google_translation, LOCATE('-', a.lang_google_translation) + 1)
WHERE a.lang_google_translation REGEXP '^[a-z]+-[a-z]+' ) LIMIT 20


来源:https://stackoverflow.com/questions/12637193/multiple-table-delete-limit

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