id value
1 50
2 60
3 55
select max(value) from tablename;
Generally we know, we will get 60, but I need the next value 55.
How do I get the value 55 using SQL?
Generally we know, we will get 60, but I need the next value 55. How do I get the value 55 using SQL? |
||||
|
Another way would be to do offset (SQL Server 2012 or later):
|
|||||||||
|
|
To get the value from the highest row as ordered by
To get the second highest value in the table you can use
|
|||||
|
|
A generic solution can be like below:
Here you can also define the range like RowNum >= 10 AND RowNum <= 20. And it will give you 10th to 20th rows with all required column. |
|||
|
|
|
You have the usual top trick such as:
Or you can also use CTE like:
Or, if you use recent version of SQLServer (>= 2012), the lag function.
|
|||||
|
id? – Philᵀᴹ 6 hours ago