Mazatec
Mazatec

Reputation: 11649

mysql- can I do INSERT IGNORE with multiple values?

I have the following code:

INSERT IGNORE INTO unsubscribes (email)
VALUES ([email protected]),([email protected]),([email protected]),([email protected])

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),([email protected]),([email protected]),(another' at line 1

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

Upvotes: 11

Views: 16383

Answers (2)

Roshan
Roshan

Reputation: 2059

INSERT IGNORE INTO unsubscribes (email) 
VALUES ('[email protected]'),('[email protected]'),('[email protected]'),('[email protected]');

with the above query i don't find any issues. I think that you have missed quotes to enclose string.

Upvotes: 2

Shakti Singh
Shakti Singh

Reputation: 86366

Put the values inside quotes.

This will work

INSERT IGNORE INTO unsubscribes (email) 
VALUES ('[email protected]'),
       ('[email protected]'),
       ('[email protected]'),
       ('[email protected]')

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

Upvotes: 17

Related Questions