Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..

I have table person(Id,Name,Amount). I want to select records from table with distinct name with their id and Amount.

Like
Id Name Amount
1 ABC 2000
2 XYZ 6000
3 ABC 3000
4 PQR 4000

then result

Id Name Amount
1 ABC 2000
2 XYZ 6000
4 PQR 4000

Thanks in advance.. :)
Posted
Updated 22-Dec-12 6:01am
v3

1 solution

Try
SQL
SELECT P.Id, P.Name, P.Amount FROM person P
INNER JOIN 
(
   SELECT Min(Id) AS Id, Name FROM person
   GROUP BY Name
) T ON P.Id = T.Id
 
Share this answer
 
Comments
Dhananjay Borde 22-Dec-12 12:05pm    
Thank You so much. Its working... :)
__TR__ 22-Dec-12 13:20pm    
You are welcome.
Surendra0x2 22-Dec-12 12:10pm    
+5 :)
__TR__ 22-Dec-12 13:20pm    
Thanks.
Jibesh 22-Dec-12 18:55pm    
my 5 too. for impressing OP :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900