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
 Distinct or Group By

Author  Topic 

paull
Yak Posting Veteran

50 Posts

Posted - 2009-03-19 : 10:57:11
Hi, I have searched the forums but couldn't find the answer to this simple question!!!

Is it possible to SELECT * and group by on one variable, so you only get one instance of a code in that column irrespective of what is in the other cols?

Everything I try ouputs a unique row across all columns so I still get multiples of the column I want!!

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 11:03:25
for that what you need to do is this

SELECT t.*
FROm YourTable t
INNER JOIN (SELECT yourcol,MAX(pk) AS latest
FROM YourTable
GROUP BY yourcol)t1
ON t1.yourcol=t.yourcol
AND t1.latest=t.pk

here pk is your primary key or any unique valued column
yourcol is column you want to get only one instance
Go to Top of Page

paull
Yak Posting Veteran

50 Posts

Posted - 2009-03-19 : 11:26:54
Thank you so much Visakh! So much to learn, dont know where to start!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 11:29:54
welcome
look this as a starting point
http://www.w3schools.com/sql/default.asp

you may also use books online that comes with sql sertver
Go to Top of Page
   

- Advertisement -