I have a MySQL database table that contains an Article ID ( primary key ) and an Article Title. I want to remove duplicate titles from the table, but keep the first occurrence of the title. I initially simply did a query for all duplicate titles:
SELECT
title,
count( id ) AS count
FROM articles
GROUP BY title
HAVING count > 1
Then I replaced all the duplicate titles with a blank using a foreach loop and this command:
UPDATE articles
SET title = ''
WHERE title = '$duplicate_title'
I’d like to update the articles table and replace all duplicate titles except the first entry, based on the Article ID ASC using something like this. The problem is that OFFSET doesn’t seem to work in an UPDATE. Is there a way to do this in a single query?
UPDATE articles
SET title = ''
WHERE title = '$duplicate_title'
ORDER BY id ASC
OFFSET 1
This basically says