Using Distinct in SQL Select

I was looking for the meanings of some songs recently I noticed there are virtually no sites out their with song means like lyrics sites. It’s probably due to lyrics being a lot more readily available and popular than meanins but I see a gap for a potential new website there. With that in mind I set about thinking how I can adapt my existing lyrics database to do it.

What I would normally do to list artists and albums, etc would be to use distinct. But that would mean I could only get one column out of the database and I need to check to see if there is anything in the meanings column as for most of the songs in the lyrics database, there won’t be. The problem is that distinct check all columns listed not just the first.

On looking around for the answer, the best thing I could find is located here, on the SitePoint Forums. I am hoping it will do what I want – select everything from the database but only where there is a unqiue artist name.

select * from yourtable where lastnamein ( select lastname from yourtable group by lastname having count(*) > 1 )

Looks crazy to be but I am willing to give it a go. I will keep you posted on how it turns out.
Timeline

Newsletter

Don't have time to check my blog? Get a weekly email with all the new posts. This is my personal blog, so obviously it is 100% spam free.

Metadata

This entry was posted on Sunday, August 1st, 2004 at 5:55 pm and is filed under Life. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.