MySQL Forums
Forum List  »  Newbie

Query Help
Posted by: Trevor Wilcox
Date: January 21, 2019 10:08PM

I have a table (wp_usermeta) which has a column called meta_key.

For the sake of example, there are two meta_key records called first_name and last_name.

I am simply trying to display the associated values of these records in a table where other conditions have also been set. I'm not trying to make these values a part of the WHERE condition, but rather somehow part of the SELECT statement so that they just get displayed.

I know the following is wrong, but it should give an idea of what I'm trying to achieve. The query works with Lines 4 & 5 removed to display User_Login and Display_Name for users that have wp_capabilities like level1. However in trying to do what I am, it obviously doesn't work.

Any advice would be very much appreciated.


SELECT DISTINCT
wp_users.`user_login`,
wp_users.`display_name`,
wp_usermeta.`meta_key` = 'first_name' AS FirstName,
wp_usermeta.`meta_key` = 'last_name' AS LastName,

FROM wp_users
LEFT JOIN wp_usermeta
ON wp_usermeta.`user_id` = wp_users.`ID`
WHERE 1=1
AND wp_usermeta.`meta_key` = 'wp_capabilities'
AND wp_usermeta.`meta_value` LIKE '%level1%'

Options: ReplyQuote


Subject
Written By
Posted
Query Help
January 21, 2019 10:08PM
January 21, 2019 10:16PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.