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.
| 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 thisSELECT t.*FROm YourTable tINNER JOIN (SELECT yourcol,MAX(pk) AS latest FROM YourTable GROUP BY yourcol)t1ON t1.yourcol=t.yourcolAND t1.latest=t.pk here pk is your primary key or any unique valued columnyourcol is column you want to get only one instance |
 |
|
|
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!!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|