SQL集合运算(并、交、差)

集合运算

unionintersectexcept对应于∪、∩、-运算

并运算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)
上一篇:笔记6分支循环


下一篇:第一次Blog