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 2005 Forums
 Transact-SQL (2005)
 Distinct record

Author  Topic 

ersantosh1
Starting Member

6 Posts

Posted - 2012-10-08 : 06:39:38
i have data in table like:-

A B_name C_REM D_s_id E_Z_id F_time
1 XX YY 12345 7890 12:30:30
2 XX YY 12345 7890 12:30:30
3 XX YY 88888 2222 12:30:30
4 XX YY 88888 2222 12:30:30

i record 1 and 3 record by distinct them as D_s_id and E_Z_ID

plz help

thanks
santosh

srahangdale

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-08 : 06:48:02
[code]SELECT * FROM
(
SELECT *,
ROW_NUMBER() OVER (PARTITION BY D_s_id,E_Z_id ORDER BY A DESC) AS RN
FROM
YourTable
) s
WHERE RN=1[/code]
Go to Top of Page
   

- Advertisement -