0

I have a table that is like this:

user_num, attending, processed
3243, 1, 0
5821, 1, 1
5821, 1, 0
5821, 1, 0
1482, 0, 1

What I need to do is add a constriction to user_num to not allow duplicates, but before I can do so, I need to delete all duplicates for that column. I see TONS of examples online for deleting duplicate rows, but I am struggling to find a place where I can just get rid of all duplicates for a certain column, so in this example I would like the outcome to be.

user_num, attending, processed
3243, 1, 0
5821, 1, 1
1482, 0, 1

Honestly I don't care if 5821 has a 0, 0 or a 1, 0 or a 0, 1 or a 1, 1 because every time they go to the page it copies their user settings from another table. I just need a script where I don't have any duplicates of a particular column (user_num) but I still need all the columns in the table.

shellwe
  • 105
  • 4
  • 16
  • Also this table does not currently have any unique identifiers and for the sake of all the code that is using this I would rather avoid having to add additional columns. – shellwe Mar 25 '16 at 16:34
  • 1
    If you can't add a column to a table for fear of breaking code then you really need to sort out your development process. That kind of refactoring should be a pretty simple and painless thing to do. – Tom H Mar 25 '16 at 16:37
  • @shellwe You can update your question, no need to add a comment. You said you only want to delete the duplicates in one column, not the whole row. Are you saying you want to delete the row if the user_num is not unique? – Trisped Mar 25 '16 at 16:37
  • You using INSERT query each time? Maybe you need to check if users exists and usr update query – Veniamin Mar 25 '16 at 16:37
  • This answer in the dupe doesn't require any unique identifier http://stackoverflow.com/a/3822833/73226 – Martin Smith Mar 25 '16 at 16:38
  • @Trisped I need to delete the entire row if a value in the user_num column is a duplicate, like in my second example. – shellwe Mar 25 '16 at 17:00
  • @TomH The project this links to is part of a very large project and the info that is sent in when they go to the page is another team's project so changing the structure of the table would most likely be fine but if it can be avoided that would be ideal. – shellwe Mar 25 '16 at 17:02
  • Haha, marked as duplicate, the irony :) – Jeff.Clark Mar 25 '16 at 17:36

0 Answers0