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
 group by?

Author  Topic 

kt
Yak Posting Veteran

88 Posts

Posted - 2014-08-22 : 15:34:21
Hi,

the results I have is

rank Ord Line DateDel Recpt Item Sup
---- ----- ------ ------ ----- ---- ------
1 ABC 10 2014-04-23 C041804 zzz 123
2 DEF 80 2014-04-14 M041258 zzz 123
2 GHI 40 2014-04-14 K041844 zzz 123

I want to get only first two because last two it has the same date of 2014-04-14, what can I do?

thanks
kt

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-08-22 : 16:25:08
[code]SELECT * FROM
(
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY DateDel ORDER BY Ord) AS RN
FROM
(
YourOriginal Query here
) s1
) s2 WHERE RN = 1;[/code]
Go to Top of Page

kt
Yak Posting Veteran

88 Posts

Posted - 2014-08-22 : 16:51:00
thanks alot.
Go to Top of Page
   

- Advertisement -