mysql - SQL query: how to group items correctly? -


could please modify following sql query work in mysql? currently, error message table t1 doesn't exist. table columns "post_title", "name1", "url1".

if helps query can tested on wordpress cms database

select t1.post_title,        (select meta_value t1 t1.meta_key='name1_class' limit 1) name1,        (select meta_value t1 t1.meta_key='url1_class' limit 1) url1   (select pm.post_id id, pm.meta_key, pm.meta_value, p.post_title, t.slug wp_2_postmeta pm     inner join wp_2_posts p on pm.post_id = p.id     inner join wp_2_term_relationships tr on tr.object_id = p.id         inner join wp_2_term_taxonomy tt on tr.term_taxonomy_id = tt.term_taxonomy_id     inner join wp_2_terms t on t.term_id = tt.term_id     post_type='footercolumn' , post_status='publish' , pm.meta_key '%class') t1  

the subquery t1 table in "from" clause produces dataset this:

'id', 'meta_key',  'meta_value', 'post_title', 'slug'  '18', 'name1_class', 'our work', 'who are', 'column1'  '18', 'url1_class', '/work.html', 'who are', 'column1'  '18', 'name1_class', 'our team', 'about', 'column2'  '18', 'url1_class', 'team.html', 'about', 'column2 

i result table be:

'title',      'name1',     'url1' 'who are', 'our work',  'work.html' 'about',      'our team',  'team.html' 

thanks

looks you're trying emulate cte (common table expression) using subselects, can't quite think of way make work.

the news if can use aggregate find data, don't need subselect.

select t1.post_title,        max(case when meta_key='name1_class' meta_value end) name1,        max(case when meta_key='url1_class' meta_value end) url1   (select pm.post_id id, pm.meta_key, pm.meta_value, p.post_title, t.slug          wp_2_postmeta pm         inner join wp_2_posts p on pm.post_id = p.id         inner join wp_2_term_relationships tr on tr.object_id = p.id             inner join wp_2_term_taxonomy tt             on tr.term_taxonomy_id = tt.term_taxonomy_id         inner join wp_2_terms t on t.term_id = tt.term_id         post_type='footercolumn' , post_status='publish' , pm.meta_key                '%class') t1  

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -