Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Query MySQL database find missing email addresses

I am trying to extract email addresses from given list, that not persists in MySql database. My query:

SELECT * 
FROM users 
WHERE `user_email` IN ('myemail@email.com', 'my2email@email.com', 'my3email@email.com')

First two email addresses are in database, but the last one is not. My target is to print only emails that are NOT in database. How is that possible?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

SELECT * 
FROM (SELECT 'myemail@email.com' user_email
      UNION ALL
      SELECT 'my2email@email.com'
      UNION ALL
      SELECT 'my3email@email.com') emails_to_check_for
LEFT JOIN users USING (user_email)
WHERE users.user_email IS NULL;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading