MySQL: Update a value if an another value for this line is equals to a value from a 'list' of 10 000 values
I must update an (emails) fields in Mysql (compagnie) table. I search a solution to compare each lines with a list (CSV file) that contains only unsubscribed emails. If the emails is unsubscribed, then I must update开发者_运维百科 (newsletter) fields for this line and set to NO. Probably, that I should import my CSV file with 10,000 inscribed emails in a column of my table or one another table to make a comparison? Also, I think create an index and lock the table.
E.g. to make an update but I must enter the email manually:
CREATE INDEX idx ON compagnie (emails);
LOCK TABLES compagnie WRITE;
UPDATE compagnie SET newsletter='NO' WHERE email='user@mail.com';
UNLOCK TABLES compagnie WRITE;
The easiest way is to have two columns, unsubscribe and subscribe. Using join to update the subscribe table.
UPDATE subscribe
SET newsletter = "No"
FROM
subscribe
Join unsubscribe ON (subscribe.email = unsubscribe.email);
No need, just implode the list of email and do comparison in single query like
CREATE INDEX idx ON compagnie (emails);
LOCK TABLES compagnie WRITE;
UPDATE compagnie SET newsletter='NO' WHERE email IN( ... );
UNLOCK TABLES compagnie WRITE;
...
will be replaced by all emails you have in the CSV
such as IN('email1','email2','email3',...)
精彩评论