Search code examples
mysqlinsert

mysql- can I do INSERT IGNORE with multiple values?


I have the following code:

INSERT IGNORE INTO unsubscribes (email)
VALUES (john@john.com),(kevin@kevin.com),(mike@mike.com),(another@gmail.com)

but it repeatedly returns an error...

The error is:

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 '@john.com),(kevin@kevin.com),(mike@mike.com),(another' at line 1

Any ideas why? It is legal to do insert ignore with multiple values right?


Solution

  • Put the values inside quotes.

    This will work

    INSERT IGNORE INTO unsubscribes (email) 
    VALUES ('john@john.com'),
           ('kevin@kevin.com'),
           ('mike@mike.com'),
           ('another@gmail.com')
    

    Note that varchar, text etc values should be inside the quotes.