我有2个不同的表,每个表都有一个名为product_type的列.如何跨两个表获取product_type的DISTINCT值?只是为了澄清一下,如果两个表的product_type都是"diamond",我只希望它返回一次.基本上好像两个表组合在一起,我从中选择了不同的product_type.
谢谢!!
alb*_*ein 18
对包含union的子查询使用distinct
select distinct product_type from (
select product_type from table 1
union
select product_type from table 2
) t
Run Code Online (Sandbox Code Playgroud)
使用distinct和union:
select distinct product_type from table1
union
select distinct product_type from table2
Run Code Online (Sandbox Code Playgroud)
合并结果时,联合将删除重复项。