MySQL Forums
Forum List  »  Newbie

Re: Query for finding keys (IDs) that only have one of two values associated with it
Posted by: Peter Brawley
Date: April 19, 2014 01:53PM

select 
  post_id, 
  sum( if(meta_key='_VenueVenue',1,0)) as VenueVenues,
  sum( if(meta_key='_VenueLat',1,0) ) as VenueLats
from tbl
group by post_id
having VenueVenues>0 and VenueLats=0;

To suppress the 2nd & 3rd columns ...

select post_id 
from (
  select 
    post_id, 
    sum( if(meta_key='_VenueVenue',1,0)) as VenueVenues,
    sum( if(meta_key='_VenueLat',1,0) ) as VenueLats
  from tbl
  group by post_id
  having VenueVenues>0 and VenueLats=0
) x;

Options: ReplyQuote




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.