Created
June 1, 2021 03:15
-
-
Save jenny-codes/c6375eca6dc269ca9a9dafc340c3ad40 to your computer and use it in GitHub Desktop.
SQL query to list records with duplicate fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# table: _TABLE_ | |
# possibly duplicated field: _FIELD_ | |
select id, _FIELD_, duplicate_count from ( | |
select id, _FIELD_, | |
count(_FIELD_) over (partition by _FIELD_) as duplicate_count | |
from _TABLE_ where _FIELD_ is not null | |
) as processed_table | |
where duplicate_count > 1 | |
order by duplicate_count DESC, _FIELD_; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment