sql - Resolved: Query that returns the output where one column matches all the values in another column -


using oracle developer, i've run query results in following table. want results column1 matches values columns 2 (3,4,8). output 2, 3, not 4. i'm sure there way bring result without hard coding it? i'm thinking sort of self-join?

    select column1, column2     table1     column1 in (         select column1         table2         depth >= 100)     order column2; 

output:

    column1   column2     3          2     8          2     4          2     3          3     4          3     8          3     4          4 

table2

    column1     area_name       depth     1           lake            40     2           river           50     3           ocean           150     4           cliff           150     5           mountain        90     6           construction    60     7           building        50     8           random          100     9           random     50     10          1     80 

needed output:

    column2     2     3 

ok, looking for:

    select table1.column1     table1         inner join table2          on table1.column2 = table2.column2         table2.depth >= 100     group boat_id     having count(*) >= (         select count(*)          table2         depth >= 100);  

updated

with qry (   select column1, column2     table1    column1 in (         select column1           table2          depth >= 100) )  select t1.column2   qry t1 left join qry t2     on t1.column1 = t2.column1 , t1.column2 = t2.column2  group t1.column2 having count(*) = (select count(distinct column1) qry) order t1.column2 

output:

| column2 | ----------- |       2 | |       3 | 

sqlfiddle


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -