Get multiple values from the postmeta table in a sql query

by dingo_d   Last Updated December 07, 2017 10:08 AM

I want to show multiple values from a rather complex query

SELECT p.post_title,, pm.meta_value
  (CASE WHEN pm.meta_key = 'network_branch_atm_id' THEN pm.meta_value END) AS atmID,
  (CASE WHEN pm.meta_key = 'network_address' THEN pm.meta_value END) AS atmAddress
FROM `wp_posts` p
  LEFT JOIN wp_term_relationships trr ON p.ID = trr.object_id
    LEFT JOIN wp_term_taxonomy tax ON trr.term_taxonomy_id = tax.term_taxonomy_id
    LEFT JOIN wp_terms t ON tax.term_taxonomy_id = t.term_id
    LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id
      p.post_type = 'network-type' AND t.slug = 'atm';

Basically, I need to show posts from specific category, and I want to show 2 values from the post meta table, but I keep getting error when I run it in phpMyAdmin:

#1370 - execute command denied to user 'wp'@'localhost' for routine 'pm.meta_value'

Any idea what is wrong with the query? When I remove the CASE statements, I get good results, but I would like to show these two values as well.

Tags : mysql sql

Related Questions

wp_admin edit.php slow with lots of queries

Updated June 11, 2015 06:03 AM

Add value to array in database

Updated April 22, 2015 21:03 PM