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

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?



Solution 1:[1]

create a temporary table and insert all the email ids that you want to check

create table check_emailid(email_id varchar(255))

insert into check_emailid(email_id )
values('[email protected]') 
values('[email protected]')
values('[email protected]')

select * 
from check_emailid 
where email_id not in (SELECT user_email
                       FROM users)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Moulitharan M