I have a list of email addresses in the Java code and I would like to check if any of these already exists in the MySQL database.
For example:
I want to know if any of the above email ids is already present in the table, and if they do, I would like to pull or separate them out.
I am not sure how to achieve this. Should I try this in Java or use SQL to achieve the desired result?
This SQL expression will tell you if an email exists or not:
SELECT IF (COUNT(*) > 0, 'Exist', 'Not exist')
FROM email_table
WHERE email = '[email protected]';
If you just want the number of occurrences you can do this:
SELECT COUNT(*)
FROM email_table
WHERE email = '[email protected]';
If you want to check for multiple values at a time you can do this:
SELECT COUNT(*)
FROM email_table
WHERE email IN ('[email protected]', '[email protected]');
If you want to see which IDs are found:
SELECT email
FROM email_table
WHERE email IN ('[email protected]', '[email protected]');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With