I have a plethora of duplicate comments in my WordPress database, specifically table wp_comments. Of course, those comments have a different IDs. I’d now like to de-dupe those comments based on the field comment_date which would identify all comments posted on the same date and time. I don’t care which one of the duplicates remain.
What SQL query do I have to use to achieve this?
Thanks!
EDIT: I don’t want to delete a specific comment date across the table, instead I want the database to scan for duplicate dates and remain with only one entry.
You could do a select all query and then loop through those. While in the loop do a query that delete anything that is the same and doesn’t have the ID of current index. Backup first.
Update:
I prefer to keep this kind of code in a separate file in the root directory.
SO make a new file in root and call it whatever you want and then add this code. Run the file AFTER YOU BACKUP your comment and comment meta tables.
Update:
I prefer to keep this kind of code in a separate file in the root directory.
SO make a new file in root and call it whatever you want and then add this code. Run the file AFTER YOU BACKUP your comment and comment meta tables.
first count number of comments …
then store the result in a variable … for example $comment_count
then …
replace N with $comment_count-1