-- Union 是当存在重复记录行时,只取一行(也就是说重复记录行只显示一条),同时进行默认规则的排序;
-- Union all 是不管你有没有重复,都显示出来,不进行排序;
-- Intersect,对两个结果集进行交集操作,不包括重复行,同时进行默认规则的排序;
-- Minus,对两个结果集进行差操作,不包括重复行,同时进行默认规则的排序。
可以在最后一个结果集中指定Order by子句改变排序方式。
1.
select ntitle,ntid from newinfo where ntid='1010'
union
select ntitle,ntid from newinfo where ntid='154'
2.
select ntitle,ntid from newinfo where ntid='1010'
union all
select ntitle,ntid from newinfo where ntid='154'
3.
select ntitle,ntid from newinfo where ntid='1010'
Intersect
select ntitle,ntid from newinfo where ntid='154'
4.
select ntitle,ntid from newinfo where ntid='1010'
Minus
select ntitle,ntid from newinfo where ntid='154'
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23760110/viewspace-1117599/ ,如需转载,请注明出处,否则将追究法律责任。