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 |
Apples
Posting Yak Master
146 Posts |
Posted - 2013-01-11 : 15:48:15
|
I have a querySELECT *FROM tblMyTablethat returns these results:ID | TypeID | Name----------------------------------1 | 1 | AAA2 | 1 | BBB3 | 2 | CCC4 | 4 | DDD5 | 5 | EEE6 | 5 | FFF7 | 5 | GGGI'd like to filter the results so that there are only distinct TypeIds, so that the results returned are:ID | TypeID | Name----------------------------------1 | 1 | AAA3 | 2 | CCC4 | 4 | DDD5 | 5 | EEEHow can I change my query to do that? |
|
adry_fab
Starting Member
1 Post |
Posted - 2013-01-11 : 16:38:36
|
SELECTMIN(ID), TypeID,min(Name)FROM tblMyTable GROUP BY TypeID |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-12 : 03:27:31
|
[code]SELECT ID,TypeID,NameFROM(SELECT ROW_NUMBER() OVER (PARTITION BY TypeID ORDER BY ID) AS Seq,*FROM table)tWHERE Seq=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|