Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have the table like this


create table testtest
(
id int,
name char(16),
amount char(16))

insert into testtest values(3,'aa',100),(2,'aa','120'),(3,'bb','100'),(4,'bb','120'),(5,'cc','100'),(6,'cc','120')


id name amount
1 aa 100
2 aa 120
3 bb 100
4 bb 120
5 cc 100
6 cc 120
3 aa 100


I need the result like this


aa 2 120
bb 4 120
cc 6 120

Note: i need the result maximum of amount and that id
Posted

Try:
SQL
SELECT name, id, MAX(amount) FROM testtest
GROUP BY name
 
Share this answer
 
try this one
SQL
select name,MAX(id) as [ID],MAX(amount) as[MAXIMUM AMOUNT] from testtest
group by name

this will give you the output that you have desired
And there is an entry wrong in the insert statement that you have written. First entry must be insert into testtest values(1,'aa',100) instead of (3,'aa',100)
 
Share this answer
 
SQL
SELECT name,MAX(amount) FROM testtest
GROUP BY name

Or 

Select * From testtest Where Amount = 120
 
Share this answer
 

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