SQLite 中的 DISTINCT 子句 [英] DISTINCT clause in SQLite

查看:26
本文介绍了SQLite 中的 DISTINCT 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我发现 SQLite 不支持看起来特定于 postgresql 的 DISTINCT ON() 子句.例如,如果我有包含 ab 列的表 t.我想选择具有不同 b 的所有项目.以下查询是 SQLite 中唯一一种正确的方法吗?

Recently i found that SQLite don't support DISTINCT ON() clause that seems postgresql-specific. For exeample, if i have table t with columns a and b. And i want to select all items with distinct b. Is the following query the only one and correct way to do so in SQLite?

select * from t where b in (select distinct b from t)

示例数据:

a | b
__|__
1   5
2   5
3   6
4   6

我期望的回报:

a | b
__|__
1   5
3   6

推荐答案

使用:

  SELECT MIN(t.a) AS A,
         t.b
    FROM TABLE t
GROUP BY t.b

这篇关于SQLite 中的 DISTINCT 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆