select tmpid,url from table1 where table1.uptime >'2016-02-01' and table1.uptime <'2016-03-01';
select tmpid,url from table2 where table2.uptime >'2016-02-01' and table2.uptime <'2016-03-01';
select tmpid,url from table1 where table1.uptime >'2016-02-01' and table1.uptime <'2016-03-01'union select tmpid,url from table1 where table2.uptime >'2016-02-01' and table2.uptime <'2016-03-01';
以上三条语句 union以后的结果有8300条 但是两条语句单独执行的查询出来的数据分别是8600多条和2000多条 ,union不是取并集操作么 为何取出来的结果数据量会少于单独的
union
会把两个查询中出现的重复的值合并,也就是说如果结果中有相同的行,union
只会返回其中一个。
如果想返回所有的行,包括重复的,需要使用union all
。