SQL集合运算(并、交、差)
作者:互联网
集合运算
union
、intersect
、except
对应于∪、∩、-运算
并运算union
union
自动去除重复,如果想保留所有重复,则用union all
代替union
(select course_id
from section
where semester = 'Fall' and year = 2009)
union
(select course_id
from section
where semester = 'Spring' and year = 2010)
交运算intersect
intersect
自动去除重复,如果想保留所有重复,则用intersect all
代替intersect
(select course_id
from section
where semester = 'Fall' and year = 2009)
intersect
(select course_id
from section
where semester = 'Spring' and year = 2010)
差运算
except
在操作前自动去除输入重复,如果想保留所有重复,则用except all
代替except
(select course_id
from section
where semester = 'Fall' and year = 2009)
except
(select course_id
from section
where semester = 'Spring' and year = 2010)
标签:运算,union,SQL,course,semester,year,集合,id,select 来源: https://blog.csdn.net/jhin_lx/article/details/120721066