1.两个不同的表,现在要查询这两个表中的Id,并合并查询结果:(去年重复列)
select brandId from acc_brand union select categoryId from ACC_category
2.两个不同的表,现在要查询这两个表中的Id,并合并查询结果(保留重复列):
select brandId from acc_brand union all select categoryId from ACC_category
3.两个不同的表,现在要查询这两个表中的Id,并合并查询结果,结果中要显示出值是哪个表的:
select 'acc' as tablename, brandId from acc_brand union select 'cate' ,categoryId from ACC_category
4.两个不同的表,现在要查询这两个表中的Id,并合并查询结果, 查询结果去年Id重复的值 :
select * from (select *,row_number() over(partition by brandId order by brandId) as rowIndex from
(select 'acc' as tablename, brandId from acc_brand union select 'cate' ,categoryId from ACC_category) as result) as a
where a.rowindex=1
注:row_number() over(partition by 列名 order by 列名) 对分组结果进行排序