I have got a database with movies and it's links. One movie may has more links. Unfortunately some of them has the same link twice.
For example:
row1 Alien vs. Predator http://www.avplink1
row2 Alien vs. Predator http://www.avplink1
row3 Alien vs. Predator http://www.avplink2
row4 Alien vs. Predator http://www.avplink3
row5 Minions http://www.minionslink1
row6 Minions http://www.minionslink1
I would like to delete that rows which are more than one in the table, but keep one of them. So I would like this:
row1 Alien vs. Predator http://www.avplink1
row3 Alien vs. Predator http://www.avplink2
row4 Alien vs. Predator http://www.avplink3
row5 Minions http://www.minionslink1
How can I write an SQL query which delete these rows? Thanks!
EDIT:
I solved with this code:
DELETE a
FROM links a
JOIN (SELECT MIN(id) id, movielink
FROM links
GROUP BY movielink) b ON a.movielink= b.movielink
AND a.id <> b.id
Thanks everyone the help!