1

I'm trying to run a SQL query from a WordPress database. Basically, I need to get the email address of all users from the wp_users table and then check to see if those users have a value that is not null in the row 'agent_name' in the wp_usermeta table. So something like this pseudo code SELECT user_email FROM 'wp_users' and SELECT agent_name FROM 'wp_usermeta'. The goal is to have the query printed out in a csv (that part I can figure out). You can see an example of the kind of output I'm looking for in this screenshot:

enter image description here

I hope that makes sense.

0

1 Answer 1

1

You should use an INNER JOIN to achive this:

SELECT u.user_email, m.meta_value FROM wp_users u 
INNER JOIN wp_usermeta m ON m.user_id = u.ID && 
           m.meta_key = 'agent_name' && 
           m.meta_value IS NOT NULL
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, I just tried it and I'm getting no results with an error Uknown column 'm.agent_name' in 'field list'
@Christian - Oooops, It should be m.meta_value in the field list, updated my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.