deleting rows with same value in a single column

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

deleting rows with same value in a single column

Post by Smudly »

I have a mysql table that looks like this:

id int(11) autoincrement
artist varchar(50)
title varchar(50)

I need to check for any rows that have the same titles.
So for example, if I had the following rows:

1 - Bob - Hello World
2 - Charlie Brown - Theme Song
3 - Joe - Hello World
4 - Joe - Is Cool
5 - Bob - Magic Dude

The query would display Row 1, and Row 3 as duplicates. Any idea how I can do something like this?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: deleting rows with same value in a single column

Post by requinix »

Code: Select all

SELECT * FROM `table` GROUP BY `title` HAVING COUNT(1) > 1
Post Reply