SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Only one row from per two columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Burzy
Starting Member

6 Posts

Posted - 06/28/2012 :  02:21:07  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8515 Posts

Posted - 06/28/2012 :  02:28:44  Show Profile  Visit webfred's Homepage  Reply with Quote
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 - 06/28/2012 :  03:23:08  Show Profile  Reply with Quote
Big thanks for Your help, It's working! :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47189 Posts

Posted - 06/28/2012 :  16:21:07  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000