SQL: Finding Duplicate IDs

Use the following SQL snip to find duplicated ID or columns on tables. This may necessary when trying to promote a column to a primary key or when attempting to add a unique index.

select distinct id,count(id) from invoice_item group by id having count(id) > 1;

Results may be like:

  956 |     2
  957 |     2
  958 |     2
  959 |     2

Loading Comments from Disqus...