Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
how to find second largest number through a query
Posted

 
Share this answer
 
Try this:

SQL
USE yourdatabase;
GO
SELECT TOP 1 yourNumber
FROM (
SELECT DISTINCT TOP 4 yourNumber
FROM yourtable
ORDER BY yourNumber DESC) A
ORDER BY yourNumber
GO


hope it helps :)
 
Share this answer
 
Here is how you do it.. Check this link[^]
 
Share this answer
 
Depends on your needs, you can use 2 ranking functions[^]:
1. ROW_NUMBER()[^]
or
2. RANK()[^]
Example:
SQL
SELECT *
FROM (
    SELECT *, ROW_NUMBER() OVER(ORDER BY Field1) AS RowNo
    FROM Table1
) AS T
WHERE RowNo = 2
 
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