I have a task to get the second biggest number using sql query. I know that we can get the biggest number using SQL very easily: select Max(NumColumn) from TableName
For example, I have the following records:
If I use "select Max(NumColumn) from aTable", I will get the number: 180.
But I need to use SQL to the second biggest number: 110.
select ROW_NUMBER() over (order by col asc) as 'rowNum', col
from [table] ) withRowNum
where rowNum = 2
SELECT MAX(NumColumn) FROM aTable WHERE NumColum < (SELECT MAX(NumColumn) FROM aTable)
select min(NumColumn) from TableName where NumColumn in (select TOP 2 (NumColumn) from TableName order by NumColumn desc)