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
 Unique Rows

Author  Topic 

JayMac
Starting Member

3 Posts

Posted - 2011-03-28 : 16:37:34
Hi, Im kind of a new to sql i can do basic stuff, usually i just do websites lol
so basically i have a table with columns ID,desc1,desc2,date1,date2
and im trying to pull only rows where id = 1 and desc1 is unique, but the column date2 always has different data so i cant use the distinct because i still get a lot of dups.
Any help will be greatly appreciated, sorry for the noob question lol

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2011-03-28 : 16:47:00
Do you have to include that field?

Hey, it compiles.
Go to Top of Page

JayMac
Starting Member

3 Posts

Posted - 2011-03-28 : 16:52:10
yes, these are the 5 fields have to be displayed. The fact that date2 is always different is throwing me off
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-28 : 17:08:10
SELECT ID, desc1, MAX(desc2) desc2, MAX(date1) date1, MAX(date2) date2
FROM myTable
GROUP BY ID, desc1
Go to Top of Page

JayMac
Starting Member

3 Posts

Posted - 2011-03-29 : 08:51:22
Thank you very much works perfectly
Go to Top of Page
   

- Advertisement -