sql中union用法

举例:select count(distinct a.thrknow) from (select distinct thrknow from  table1
lateral view explode(split(three_know,'\\^\\.\\^')) c AS thrknow
where questinnersource=4 and subject='C01'  and fastdfsurl like 'group%'  and docfastdfsurl 
like 'group%' and pngfastdfsurl like 'group%' union
select distinct thrknow from   table2
lateral view explode(split(three_know,'\\^\\.\\^')) c AS thrknow
where questinnersource=1 and isanswer=0 and isoption=0  and fastdfsurl like 'group%'  and docfastdfsurl 
like 'group%' and pngfastdfsurl like 'group%')a;

1.UNION 操作符用于合并两个或多个 SELECT 语句的结果集;

2.UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。

3.UNION将查询的字段合并在一起并自动去重;

4.UNION ALL和并结果集的字段以后允许重复;

 

 

你可能感兴趣的:(sql)