当前位置:网站首页>Union, intersection and difference operations in SQL

Union, intersection and difference operations in SQL

2022-06-26 18:15:00 yanruo06280

SQL It's not the same in China 、 hand over 、 Difference operation

1、 hand over ( Corresponding to the intersection operation in the set ,A∩B)
notes : Returns the same part of the query result, that is, their intersection , Want to keep all duplicates , Must use INTERSECT ALL Instead of INTERSECT

select * from table1) intersectselect * from table2)

2、 Difference set ( Corresponding to the difference set operation in the set ,A-B)
notes : Return the row records that are different from the second query result in the first query result ,
That is, the difference set of two results ,EXCEPT The operation automatically removes duplicates , If you want to keep all the repetitions , Must use EXCEPT ALL Instead of EXCEPT..oracle of use minus Realization

select * from table1) exceptselect * from table2)

3、 Combine ( Corresponding to the union operation in the set ,AUB)
notes :UNION The operation automatically removes duplicates , Want to keep all duplicates , You have to use UNION ALL Instead of UNION

select * from table1) unionselect * from table2)
原网站

版权声明
本文为[yanruo06280]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261806550250.html