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

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

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