SQL Transpose of WordPress meta tables (key-value pairs)

Here is sample demo sql:

select * from (

SELECT m.user_id,
MAX(CASE WHEN m.meta_key = ‘first_name’ THEN m.meta_value ELSE NULL END) AS first_name,
MAX(CASE WHEN m.meta_key = ‘last_name’ THEN m.meta_value ELSE NULL END) AS last_name
FROM wp_usermeta m
GROUP BY m.user_id

) as s where first_name = ‘John’

Source: http://stackoverflow.com/questions/3392956/sql-how-to-transpose

Posted in Uncategorized. Leave a Comment »

Share your thoughts & feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: