Skip to content
Advertisement

Retrieve a row which has maximum value for one column

I have this query:

select * 
from COMMISSION  
where dealer_id in (select dealer_id from DEALER where COM_NAME like 'abcdef')  

This query returns two rows which include column STATUS_ID with values 100, 102. I want to retrieve the row which has STA_ID = 102. How do I do that? Please help.

Advertisement

Answer

select top 1 id
from Commission
where dealer_id in (select dealer_id from DEALER where COM_NAME like 'abcdef')
order by Status_ID desc
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement