Question: Hi I was wondering whether someone would be able to help me with a query. I am trying to select from an EAV type table where the value is not multiple values.

Using the example below I am trying to retrieve rows where tag\_id != 1 and tag\_id != 2. So based on the data I want to return just the row containing contact\_id 3

```
Tags Table:

contact_id     tag_id 
  1             1
  1             2
  2             1
  2             4
  3             4

```

The desire result is to return a single row:

```
contact_id -> 3

```

I have tried the following queries which don't return what I am looking for so are obviously are not correct:

```
select `contact_id` from `contact_tags` where tag_id !=1 and tag_id != 2

select `contact_id` from `contact_tags` where tag_id NOT IN(1,2)

```

Any help on this. Or just a pointer in the right direction would be great.

Answer: 
may be this is what you want

```
select contact_id 
from contact_tags 
where contact_id not in (
    select contact_id from contact_tags where tag_id in (1,2)
) tmp

```
Stealing from @491243 fiddle here is a modification which returns contacts\_id which lack both tags\_id

<http://sqlfiddle.com/#!2/b2b11/19>