Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: restrictive WHERE-IN
Start with...
SQL> create table table1(person_id int,value_id int); Table created.
SQL> insert into table1 values(1,1); SQL> insert into table1 values(1,2); SQL> insert into table1 values(1,3); SQL> insert into table1 values(1,4); SQL> insert into table1 values(2,1);
NOW...Add this to the mix...
insert into table1 values(1,5);
Now run this...
SQL> select *
2 from table1
3 where person_id in ( select person_id
4 from table1 5 where value_id in ( 1, 2, 3, 4 ) 6 group by person_id 7 having count( distinct value_id ) = 4 )8 /
And you get this...
PERSON_ID VALUE_ID
---------- ----------
1 1 1 2 1 3 1 5 <------Note! 1 4