Kristian
Kristian

Reputation: 3461

Multiple-table DELETE LIMIT

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?

Upvotes: 1

Views: 2952

Answers (1)

Cosmin
Cosmin

Reputation: 1490

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

Upvotes: 2

Related Questions