sql - how to filter a table that having exactly the specified values in tsql -


i need filter table exact values. have googled day now, wonder if guys can me

i have table this:

    id  |  group id  | tax id     -------------------------     1   |  1         | 1     2   |  2         | 1     3   |  2         | 2     4   |  3         | 2     5   |  3         | 3     6   |  3         | 4     7   |  4         | 1     8   |  4         | 4     9   |  5         | 2    10   |  5         | 4    11   |  6         | 3    12   |  6         | 4 

i need group id when tax ids 2,3, , 4, group id 3.
if put tax_id in (2,3,4) these tax groups 3,5,6.
want tax group 3 only.
hope not duplicate question, since not find when google it.

you need group by clause on group_id column , having clause count distinct tax_id equal 3 tax id 2 or 3 or 4

not exists take care of condition group should contain given set if elements , not additional elements

sql fiddle

select [group_id] table1 t [tax_id] in (2,3,4) , not exists ( select 1 table1 e t.group_id = e.group_id , tax_id not in (2,3,4) ) group group_id having count(distinct tax_id) =3 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -