Search code examples
mysqlsqldelete-rowwhere-in

DELETE FROM tab WHERE name IN ( name1 , name2 ) :fails / ok: DELETE FROM tab WHERE id IN ( 1 , 2 )


Error deleting record: 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 ' name2' at line 1 **

  tab:
  __________
  id , name
  __________
   1 , name1
   2 , name2
   3 , name3



  DELETE FROM  tab  WHERE  id   IN ( 1 , 2 )
Record deleted successfully! 

but ERROR :

  DELETE FROM  tab  WHERE  name   IN ( name1 , name2 )
Error deleting record: 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 ' name2' at line 1

I like to delete the data with name1 and name2 , I do not know the id

Please help , thank you


Solution

  • If those are string values, you need single quotes:

    DELETE FROM  tab 
        WHERE name IN ('name1', 'name2')