[Solved] Delete all rows except the one with the biggest value


DELETE FROM `transactions`
WHERE id NOT IN 
(
    SELECT MAX(id)
    FROM `transactions`
    group by user_id
)

The inner query groups by each user and select only the highest ID for each. Delete all records except the IDs from the inner select.

0

solved Delete all rows except the one with the biggest value