1

I am trying to find the best way to see if multiple email addresses already exist in my database. I have a table with member id's, emails, and other info, and I need to import members but to check if members already exist. The amount of member that I will import will vary because it will be CSV files from users.

I dont want to make a really long "email LIKE OR " ... etc.

I was thinking of making a temporary table and then union that table to my members table, but worried about performance. Any other ideas?

Additional Information:

I read in a lot of names and email addresses, and I need to check if those email addresses are already in the database. But instead of making numerous calls to the DB, or a really long where clause similar to "WHERE email LIKE '' OR email LIKE '' OR ...", I wanted to find a better way or getting emails that are either already in the database.

In the end, I did something like this for the where clause:

"email IN ('" . implode( "','", $inviteEmails ) . "')"

where $inviteEmails is an array of emails I am going to insert as users for the site.

closed as unclear what you're asking by Erik Darling, RDFozz, hot2use, mustaccio, SqlWorldWide Jan 26 '18 at 1:56

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

You can use IN,

SELECT *
FROM t
WHERE email IN ('foo', 'bar', 'baz');
  • This works, for some reason when I was trying it previously it was not working. Do you know if making a temporary table would be more beneficial at a certain point? – Ice76 Jan 24 '18 at 19:45
  • Certainly if it has an index, and it's worth it – Evan Carroll Jan 24 '18 at 19:46
  • @Ice76 - Some people have reported issues using IN with huge numbers of values (like, thousands of values in a single IN clause). That's probably a case where it's worth creating the temporary table. – RDFozz Jan 25 '18 at 2:21
  • @RDFozz When absurdity strikes, SLEDGEHAMMER. ;) – Evan Carroll Jan 25 '18 at 2:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.