Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL MySQL Oracle
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.. Smile | :)
Posted 22-Dec-12 5:43am
Edited 22-Dec-12 6:01am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try
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
  Permalink  
Comments
Dhananjay Borde at 22-Dec-12 12:05pm
   
Thank You so much. Its working... :)
__TR__ at 22-Dec-12 13:20pm
   
You are welcome.
Surendra0x2 at 22-Dec-12 12:10pm
   
+5 :)
__TR__ at 22-Dec-12 13:20pm
   
Thanks.
jibesh at 22-Dec-12 18:55pm
   
my 5 too. for impressing OP :)
__TR__ at 23-Dec-12 2:46am
   
Thank you.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 343
1 _Amy 290
2 Manfred R. Bihy 200
3 Maciej Los 185
4 CHill60 180
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,347
2 Maciej Los 3,799
3 Peter Leow 3,558
4 CHill60 2,702


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100