php - can I EXCLUDE rows in my complex query where criteria is met? (combining WHERE + multi AND) -


i need results table grouped ids exist in rows field1 = , field2 not null, not rows field1 = b , field2 null. getting syntax error, don't know quite how combine these criteria...

here's i'm trying do:

select a.post_title title, a.id,      max(case when b.meta_key = 'endorser' b.meta_value end) endorser,      max(case when b.meta_key = 'trail' b.meta_value end) trail,      max(case when b.meta_key = 'townarea' b.meta_value end) townarea,      max(case when b.meta_key = 'state' b.meta_value end) state,      max(case when b.meta_key = 'start-date' b.meta_value end) startdate,      max(case when b.meta_key = 'description' b.meta_value end) description,      max(case when b.meta_key = 'organizer-name' b.meta_value end) organizer,      max(case when b.meta_key = 'info-email' b.meta_value end) infoemail      wp_posts left join wp_postmeta b on a.id = b.post_id      b.post_id in          (select post_id wp_postmeta           (meta_key = 'endorser' , meta_value not null)           , (meta_key = 'trail' , meta_value null)) group b.post_id 

and table looks this:

meta_id  |   post_id   |  meta_key  |   meta_value ---------|-------------|------------|------------   1      |     53      |  endorser  |   joe   2      |     54      |  trail     |   trail name 

so rows containing post_id 53, not 54

i'm tired, may missing simple, simple outer join?

here's fiddle: http://sqlfiddle.com/#!2/ee5420/1

you can rid of subquery using b.meta_key in ('endorser','trail') , in clause can use case null , not null criteria

select a.post_title title, a.id, (select max(meta_value) wp_postmeta meta_key = 'endorser' , post_id =a.id) endorser, (select max(meta_value) wp_postmeta meta_key = 'trail' , post_id =a.id) trail,    (select max(meta_value) wp_postmeta meta_key = 'townarea' , post_id =a.id) townarea,    (select max(meta_value) wp_postmeta meta_key = 'state' , post_id =a.id) state,    (select max(meta_value) wp_postmeta meta_key = 'start-date' , post_id =a.id) startdate,    (select max(meta_value) wp_postmeta meta_key = 'description' , post_id =a.id) description,    (select max(meta_value) wp_postmeta meta_key = 'organizer-name' , post_id =a.id) organizer,    (select max(meta_value) wp_postmeta meta_key = 'info-email' , post_id =a.id) infoemail         wp_posts       left join wp_postmeta b on a.id = b.post_id  b.meta_key  in ('endorser','trail')      , (   case     when b.meta_key = 'endorser'      b.meta_value not null      when b.meta_key = 'trail'      b.meta_value null    end ) having trail ='' 

fiddle demo


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -