oracle union query: union and union all; intersect and minus

Union query: union and union all; intersect and minus

--Joint query: union and union all; intersect and minus

select 1,2 from dual
union
select 1,2 from dual;
--union performs a union operation on multiple result sets, excluding duplicate rows, while sorting by default rules:
--1,2

select 1,2 from dual
union all
select 1,2 from dual;
--union all performs a union operation on multiple result sets, including duplicate rows, without sorting:
--1,2
--1,2

select 1,2 from dual
intersect
select 1,3 from dual;
--intersect: Perform the intersection operation on the two result sets, excluding duplicate rows, and sort by default rules:
-- The query result is empty

select 1,2 from dual
intersect
select 1,2 from dual;
--intersect: Perform the intersection operation on the two result sets, excluding duplicate rows, and sort by default rules:
--1,2

select 1,2 from dual
minus
select 1,2 from dual;
--minus: Perform a difference operation on the two result sets, excluding duplicate rows, and perform sorting by default rules:
-- The query result is empty

select 1,2 from dual
minus
select 1,3 from dual;
--minus: Perform a difference operation on the two result sets, excluding duplicate rows, and perform sorting by default rules:
--1,2

--You can specify the Order by clause in the last result set to change the sorting method

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326182275&siteId=291194637