0

I have a MySQL table with thousands of rows, and I think the algorithm that inserted those rows may have been glitched and inserted some duplicate data. Is there a quick, SQL-only way to ensure that every row is different, or do I have to manually select every row, load it into a PHP array, and check that all items are unique?

Note: I know how to do this (the long and hard way), but I'm asking if there's a shortcut or a better way.

Bluefire
  • 13,519
  • 24
  • 74
  • 118
  • Try to add a unique constraint on every column in the table. It will fail if there's duplicate data – Phil Aug 24 '16 at 00:42
  • http://stackoverflow.com/questions/5038040/mysql-make-an-existing-field-unique – Kevin Aug 24 '16 at 00:43
  • @Ghost I believe that OP was asking how to make it so that the field remains unique after future submissions. I'm asking how to look at past submissions. – Bluefire Aug 24 '16 at 00:46
  • what do you want to do when you find a duplicate? there are lots of previous questions on this topic: http://stackoverflow.com/search?q=mysql+find+duplicates –  Aug 24 '16 at 00:50
  • 1
    Select count(*), column1, column2... ColumnN group by column1, column2... ColumnN here column1, column2... ColumnN are the name of all of your columns. If anything in count comes more than one, it has been inserted myltiple times – Sumeet Gupta Aug 24 '16 at 01:00
  • @Bluefire *"I'm asking how to look at past submissions"* <- that's not how your question sounds to me, specifically *"Is there a quick, SQL-only way to ensure that every row is different"* – Phil Aug 24 '16 at 01:04
  • @Phil ensure that every row in the table is different. So every row that the table contains right now is different. – Bluefire Aug 24 '16 at 01:16

0 Answers0