Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenny-codes/c6375eca6dc269ca9a9dafc340c3ad40 to your computer and use it in GitHub Desktop.
Save jenny-codes/c6375eca6dc269ca9a9dafc340c3ad40 to your computer and use it in GitHub Desktop.
SQL query to list records with duplicate fields
# 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