消除 Postgres 中的重复行 [英] Eliminating Duplicate rows in Postgres

查看:57
本文介绍了消除 Postgres 中的重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除从 Postgres 中的 SELECT 查询返回的重复行

I want to remove duplicate rows return from a SELECT Query in Postgres

我有以下查询

SELECT DISTINCT name FROM names ORDER BY name

但这不知何故并没有消除重复的行?

But this somehow does not eliminate duplicate rows?

推荐答案

PostgreSQL 区分大小写,这可能是这里的问题DISTINCT ON 可用于不区分大小写的搜索(在 7.4 上测试)

PostgreSQL is case sensitive, this might be a problem here DISTINCT ON can be used for case-insensitive search (tested on 7.4)

SELECT DISTINCT ON (upper(name)) name FROM names ORDER BY upper(name);

这篇关于消除 Postgres 中的重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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