I have a a lot of users on my site and many of them have the same last names. I am trying to get their emails by their last name. WP stores emails in the users table and user names in the usermeta and I have been trying to use JOIN to get what I want, but I don't understand how it works and I am about to give up for the day. This is what i have after 4.5 hours.
$usersemails = $wpdb->get_results("SELECT users.user_email, usermeta.meta_value FROM $wpdb->users LEFT JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE user_status = '0' AND meta_value = 'Smith'");
Any help is appreciated, so can you please help? Thanks.