I need to get results from a table where the grouped IDs exist in rows where field1 = a and field2 IS NOT NULL, but NOT rows where field1 = b and field2 IS NULL. just getting syntax error, don't know quite how to combine these criteria...

here's what I'm trying to do:

```
SELECT a.post_title AS title, a.id,
     MAX(CASE WHEN b.meta_key = 'endorser' THEN b.meta_value END) endorser,
     MAX(CASE WHEN b.meta_key = 'trail' THEN b.meta_value END) trail,
     MAX(CASE WHEN b.meta_key = 'townarea' THEN b.meta_value END) townarea,
     MAX(CASE WHEN b.meta_key = 'state' THEN b.meta_value END) state,
     MAX(CASE WHEN b.meta_key = 'start-date' THEN b.meta_value END) startdate,
     MAX(CASE WHEN b.meta_key = 'description' THEN b.meta_value END) description,
     MAX(CASE WHEN b.meta_key = 'organizer-name' THEN b.meta_value END) organizer,
     MAX(CASE WHEN b.meta_key = 'info-email' THEN b.meta_value END) infoemail
     FROM wp_posts a LEFT JOIN wp_postmeta b ON a.id = b.post_id
     WHERE b.post_id IN 
        (SELECT Post_id FROM wp_postmeta 
         WHERE (meta_key = 'endorser' AND meta_value IS NOT NULL) 
         AND (meta_key = 'trail' AND meta_value IS NULL)) group by b.post_id

```

AND the table looks something like this:

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

```

So I would get rows containing post\_id 53, but NOT 54

I'm very tired, so I may be missing something simple, like a simple OUTER JOIN?

Here's the fiddle: <http://sqlfiddle.com/#!2/ee5420/1>