sql - Deleting duplicate rows in a database without using rowid or creating a temp table -
Several years ago I was asked during a phone interview to remove duplicate rows in the database. After several workarounds were given, I was finally told the restrictions:
- Assuming the table has a VARCHAR column
- The rumaid can not be used
- Can not use floating tables
The interviewer refused to answer me. I've been stumped since then.
After asking for many years, I'm sure there is no solution. Am I wrong ?!
And if you have any answers, will a new restriction suddenly appear? Since you mention ROWID, I think you were using Oracle. Solutions are for SQL Server.
Driven by SQLServerCentral.com
While deleting the top (1) from MyTable (1) where in VarcharColumn (select from VarcharColumn, the counting of the MyTable Group by the Vertical column (*)> 1) If @@ rowcount = 0 exit end
removes one line at a time when one set of duplicates disappears from the last line of the set Then the remaining line will not be in the sub-selection via the loop next to the next. (Big yuk!)
Also, for inspiration, see RBRI Young suggests a method that can be modified to store deeduplicated data in the same table, removes all the original rows Let's then convert back the collected deeduplicated data to the correct format. He had three columns, so what you are doing is not exactly the same.
And then it can be enabled with the cursor is not fixed and there is no time to look at it but make the cursor to draw every line out of the table, in order, and then track a variable To do that looks like the last line if the current row is the same, delete it, and set the variable in the current row.