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)
 How i can select distinct value

Author  Topic 

tooba
Posting Yak Master

224 Posts

Posted - 2011-09-20 : 13:50:04
Hi,

May be this is basic question, I have table has duplicate record here is my table structure

TABLEA = ID,LNAME,FNAME,PH

I want whole table with distinct ID, if i use SELECT DISTINCT ID FROM TABLEA, i can get what i want, but i want whole table with distinct ID, which syntax whould i use? Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-20 : 22:13:23
[code]SELECT ID,LNAME,FNAME,PH
FROM
(SELECT ROW_NUMBER() OVER (PARTITION BY ID ORDER BY LNAME,FNAME) AS Rn,ID,LNAME,FNAME,PH
FROM TABLEA
)t
WHERE Rn=1
[/code]

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

Go to Top of Page
   

- Advertisement -