Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Include other columns in SELECT DISTINCT

Author  Topic 

figmo
Starting Member

18 Posts

Posted - 2011-04-27 : 13:40:21
Table LIBRARY:
Title varchar(max)
Artist varchar(max)
DateAdded smalldatetime

I need to to a SELECT DISTINCT ARTIST FROM LIBRARY, but also need the newest date added to be returned.

Artist is not unique. There are many rows with the same artist name. So what I need is a list of all the distinct artist names (only once), but also the newest date added for that artist name.

I know this database is not normalized but its a legacy database that I really don't want to start mucking with the structure. So I'm trying to work with what I was given.

Is it possible?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-27 : 14:04:39
SELECT Artist, MAX(DateAdded) FROM LIBRARY GROUP BY Artist
Go to Top of Page
   

- Advertisement -