Reputation: 1034
I've got a table:
Is there a way to remove only the first row with a specified id? For example (on the picture) i want to remove the row with id 8, the first row with id 9 (leave the second), remove the first with the id 11 (leave the others) etc.
Upvotes: 0
Views: 461
Reputation: 780663
This will delete the first row in each post_id
group, using meta_value
as the ordering.
DELETE t1.* FROM yourTable AS t1
JOIN (SELECT post_id, min(meta_value) AS min_meta
FROM yourTable
GROUP BY post_id) AS t2
ON t1.post_id = t2.post_id AND t1.meta_value = t2.min_meta
Upvotes: 2