skip to Main Content
DELETE 
  FROM 014_terms 
 WHERE term_id IN (SELECT term_id 
                     FROM 014_term_taxonomy 
                    WHERE taxonomy LIKE 'pa_%');

I get an error

#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘WHERE term_id IN (SELECT term_id FROM 014_term_taxonomy WHERE taxonomy LIKE ‘…’ at line 1

NOTE: I am using a plain text editor and the spaces are just plain spaces.

I am using phpMyAdmin and I have tried different variations of the query wrapping the table name in single quotes, like this :

SQL query:

DELETE FROM '014_terms' WHERE term_id IN (SELECT term_id FROM '014_term_taxonomy' WHERE taxonomy LIKE 'pa_%')

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''014_terms' WHERE term_id IN (SELECT term_id FROM '014_term_taxonomy' WHERE t...' at line 1

and this

SQL query:

DELETE FROM '014_terms' WHERE term_id IN (SELECT term_id FROM 014_term_taxonomy WHERE taxonomy LIKE 'pa_%')

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''014_terms' WHERE term_id IN (SELECT term_id FROM 014_term_taxonomy WHERE tax...' at line 1

2

Answers


  1. Chosen as BEST ANSWER

    The final solution was to use backticks to wrap the table names that begin with a numerical prefix like this. Thanks to @PaulT.

    DELETE FROM `014_terms` WHERE term_id IN (SELECT term_id FROM `014_term_taxonomy` WHERE taxonomy LIKE 'pa_%');
    

    Thanks to everyone who provided feedback!!

    :-)


  2. The problem in your case seems like the table name starting from numbers/digits.

    Try updating your sql_mode:

    SET @@session.sql_mode=ANSI_QUOTES;
    

    After the above change, try executing your query.

    DELETE
    FROM 014_terms
    WHERE term_id IN
        (SELECT term_id
         FROM 014_term_taxonomy
         WHERE taxonomy LIKE 'pa_%');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search