Click here to Skip to main content
Sign Up to vote bad
good
See more: SQLMySQLOracle
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:43
Edited 22 Dec '12 - 6:01


1 solution

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

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 315
2 Slacker007 240
3 Dave Kreskowiak 212
4 Aarti Meswania 210
0 Sergey Alexandrovich Kryukov 8,893
1 OriginalGriff 7,134
2 CPallini 3,678
3 Rohan Leuva 3,036
4 Maciej Los 2,428


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