0

I need to delete from my table (TABLE_X) rows that have multiple id_B but preserving the only one that have the greatest value of id_A. The image below could be more exhaustive. I want to delete only the highlighted rows.

enter image description here

Tex'N'Duet
  • 301
  • 2
  • 13

1 Answers1

1
DELETE FROM TABLE_X
 WHERE id_A NOT IN (SELECT * 
                    FROM (SELECT MAX(n.id_A)
                            FROM TABLE_X n
                        GROUP BY n.id_B) x)

Note that the answer is taken from the following thread: Delete all Duplicate Rows except for One in MySQL?

mustafaj
  • 305
  • 1
  • 12