简体   繁体   中英

Query MySQL database for user names with their email addresses

I'm looking for a way to query all of my users (simple enough) but i need to get specific users back in the results. I'll try explain the best i can below but in short i want to use a list of email addresses as a reference to pull all users matching those email addresses.

Brief overview

I have a wordpress website which i run events from. When people sign up for the events an account is created for them. there is also another table for attendees which links these user profiles to their registrations.

As it is right now i need to get a list of people specific to one event organiser. I thought the best way to do this would be to use their email address from the attendee info and query my wp_users table for the user names.

SELECT display_name
FROM `mydatabase`.`wp_users` WHERE `user_email` LIKE 
'myemail@email.com' OR 
'mysecondemail@email.com' OR
'mythirdemail@email.com';

I've removed the real email and changed the database name.

What i am trying to achieve is a query that will run through my list of users comparing their email address that i provide to the users in the table and return any of them that match.

As it is right now it returns the first result it finds and stops.

I've got the list of emails ready to go but i am struggling to get this to work.

You need to repeat the column name like this in the where clause

SELECT display_name
FROM `mydatabase`.`wp_users` 
WHERE `user_email` = 'myemail@email.com' 
   OR `user_email` = 'mysecondemail@email.com' 
   OR `user_email` = 'mythirdemail@email.com'

or use IN()

SELECT display_name
FROM `mydatabase`.`wp_users` 
WHERE `user_email` IN ('myemail@email.com', 'my2email@email.com', 'my3email@email.com')

And like is only used when searching with wildcards. For instance

where email like '%@mydomain.com'

so i managed to figure this out a few minutes after posting this.

I didnt fix the initial issue but i managed to find and create a relationship between the two sets of data in Power BI and get the list i needed.

Thanks though.

PhilB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM