How to find duplicate records in PostgreSQL

前端 未结 4 1409
长情又很酷
长情又很酷 2021-01-29 17:17

I have a PostgreSQL database table called \"user_links\" which currently allows the following duplicate fields:

year, user_id, sid, cid

The uni

4条回答
  •  囚心锁ツ
    2021-01-29 17:52

    From "Find duplicate rows with PostgreSQL" here's smart solution:

    select * from (
      SELECT id,
      ROW_NUMBER() OVER(PARTITION BY column1, column2 ORDER BY id asc) AS Row
      FROM tbl
    ) dups
    where 
    dups.Row > 1
    

提交回复
热议问题