Sql select 不同组 2 列

Sql select distinct group 2 columns

我的table是:

title   type
a       category
b       category
d       tag
a       category
c       tag
r       tag
t       category 
d       category

我正在尝试 select 每个(类别和标签)的唯一值

我将如何合并这 2 个查询?

SELECT DISTINCT title, type FROM table WHERE type='category'

SELECT DISTINCT title, type FROM table WHERE type='tag'

实际上,这似乎可以满足您的要求:

select distinct title, type
from table
where type in ('category', 'tag')
order by type;

我添加了顺序,所以 type 都在一起了。

可以通过“分组依据”找到独特的组合

select title, type
from table
group by title, type;