Oracle database, query the data in the table contains a sub-table, the sub-data in the table is derived from the parent table are certain conditions, such as the SQL command
select * from a_table a where a.commandId in (select commandId from b_table where type = 1)
a_table parent table, b_table child table, a and b table has commandId columns, a table commandId key main association b table foreign key commandId , requires a table commandId contained in the b table commandId , and the type of black and white lists b table type 1 data
(I.e., data associated with the presence of isolated table of a table b)
It can also be used :( only one case of many of the main table duplicate happens)
select * from a_table a,b_table b where a.commandId =b.commandId (+) and b.commandId is not null and b.type = 1;
Such as (many problems arise):
or
select * from a_table a where exists(select 1 from b_table b where b.commandId =a.commandId where b.type = 1)
And exists in about the difference between:
"EXISTS, Oracle will first check the main query, sub query and then run until it finds the first match .IN, before the implementation of sub-queries, the system hangs main query first, to be sub-query execution is completed, stored in a temporary table later execute the main query.
1, UNION (and no re-set): When performing UNION, automatically remove duplicate rows of the result set, and in ascending order results in the first column.
2, UNION ALL (with a weight and set): without removing duplicate rows, and does not sort the result set.
3, INTERSECT (intersection): on the intersection of the two result sets, and results in ascending order of the first column.
select id,name,job from worker
INTERSECT
select empno,ename,job fromemp;
4, MINUS (set difference): Only in the presence of the first set, the second data set does not exist. And in ascending order results in the first column.
Therefore, there is a writing:
select * from a_table a where a.commandId in (select commandId from a_table intersect select commandId from b_table)