sql - Get groups that are exactly equal to a table -


i have query groups easily. need groups have same records table (relationship).

i'm using ansi-sql under sql server, accept answer of implementation.

for example:

table1:

id | value ---+------ 1  |  1 1  |  2 1  |  3 2  |  4 3  |  2 4  |  3 

table2:

value | ... ------+------   1   | ...   2   | ...   3   | ... 

in example, result is:

id | ---+ 1  | 

how imagined code:

select table1.id table1 group table1.id having ...? -- group has same elements of table2 

thanks in advance!

you can try following:

select t1.id table2 t2 join table1 t1 on t1.value = t2.value group t1.id having count(distinct t1.value) = (select count(*) table2) 

sqlfiddle


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -