Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear Sir,

I have a table structure like this:
col1 col2 col3
1 1 40
2 1 45
3 1 48
4 2 50
5 2 55

I want to show the Result Like(max of col3):
col1 col2 col3
3 1 48
5 2 55

I have to do this by 'SELECT Statement' only.
Thanks in advance..
Posted

1 solution

try this.. :)

SQL
with Demo as(
select max(Col3)as total,Col2 from [tbl_Demo] group by Col2)
select total,Col2,(select Col1 from [tbl_Demo] where Col3=total )as ID from Demo
 
Share this answer
 
Comments
chetna2810 17-May-14 3:26am    
thnx sir.
I got it :)
Nirav Prabtani 17-May-14 3:28am    
welcome.. :)
chetna2810 17-May-14 3:51am    
Sir Is it possible to make a 'view' to get the same result..
Nirav Prabtani 17-May-14 6:19am    
yes it is possible in this way

CREATE VIEW MyView as
with Demo as(
select max(Col3)as total,Col2 from [tbl_Demo] group by Col2)
select total,Col2,(select Col1 from [tbl_Demo] where Col3=total )as ID from Demo
chetna2810 20-May-14 4:14am    
Thanks a lot.. Again Sir :)

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