There was a programming mistake in my application that caused a table to triple its values. Here's an example, showing which rows I need to keep and delete with comments.
'id' 'uuid' 'value' 'parent' 'idx'
-------------------------------------------------------
1, uuid-1234, ROW ONE VALUE HERE, 48, 2 /* Keep this */
78, uuid-5678, ROW ONE VALUE HERE, 48, 2 /* Delete this row */
79, uuid-9999, ROW ONE VALUE HERE, 48, 2 /* Delete this row */
I obviously need to fix the application problem that caused this, but in the mean time I want to delete the two or more rows with id
s greater than the smallest id
. What SQL can I write to do this? Right now, I'm just trying to SELECT
these rows, and here is what I have:
SELECT *
FROM my_table
ORDER BY value;
This groups them together so I see the duplicated value
s, but I'm at a loss as to how to SELECT the rows with id
s greater than the smallest id
of the group for each value
.