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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Only one row from per two columns

Author  Topic 

Burzy
Starting Member

6 Posts

Posted - 2012-06-28 : 02:21:07
Hello again!:)

I have another problem. There is table:

MyTable1

ID, acc_numb, tar, stat
1, 2, 50, 30
2, 5, 50, 30
1, 5, 50, 24
3, 2, 51, 90
1, 6, 51, 90
2, 2, 50, 89
2, 3, 30, 90


I want to get result, where ('tar' and "stat') shows only one time and (ID and acc_number) shows just as info.

For example:

ID, acc_numb, tar, stat
1, 2, 50, 30
2, 5, 50, 24
2, 2, 50, 89
2, 3, 30, 90
3, 2, 51, 90

I hope You understand what I mean.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-28 : 02:28:44
select ID, acc_numb, tar, stat
from
(
select
row_number() over (partition by tar,stat order by ID) as rnum,*
from MyTable
)dt
where rnum = 1


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Burzy
Starting Member

6 Posts

Posted - 2012-06-28 : 03:23:08
Big thanks for Your help, It's working! :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-28 : 16:21:07
so you're not concerned on which values of ID, acc_numb have to be shown for a particular tar,stat group?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -