sql - 识别表中的重复数据

标签 sql postgresql

如何查找具有相同身份但不同 key 的动物,即相同的“alt_anim_ident”但不同的“animals_key”

Animals Table

最佳答案

SELECT * 
FROM thetable t                                   -- How to find animals
WHERE EXISTS (                                    -- where (different animals) exist
        SELECT * FROM thetable x 
        WHERE x.alt_anim_ident = t.alt_anim_ident -- that have same ident
        AND x.animals_key <> t.animals_key        -- but different key
        )
ORDER BY t.alt_anim_ident, t.animals_key
        ;

关于sql - 识别表中的重复数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37269325/

相关文章:

mysql - Ebean - 具有多列的 OrderBy

sql - mysql 查询与 select - where - in - join

sql - ORA-01843 : not a valid month with data type conversion

php - 我的 PHP 页面出现 SQL 语法错误

postgresql - Docker 容器在启动 Postgres DB 后立即停止

postgresql - 我可以从 Postgres 中的任意查询中获取类型吗?

asp.net - 这个SQL语句怎么写呢?

postgresql - Heroku Postgres 升级后 Flyway 无法连接到数据库

postgresql - sonar V.4.3.1 不启动postgresql

objective-c - 为了符合 MVC,我应该如何在 Cocoa 应用程序中进行数据库调用?