Below is shown the "Orders" table:
D001 |
C001 |
4/3/2007 12:00:00 AM |
150.23 |
D002 |
C003 |
1/22/2005 12:00:00 AM |
123.57 |
D003 |
C005 |
3/19/2003 12:00:00 AM |
220.43 |
D004 |
C007 |
7/21/2008 12:00:00 AM |
157.72 |
D005 |
C008 |
2/28/2009 12:00:00 AM |
223.78 |
D006 |
C011 |
3/21/2005 12:00:00 AM |
245.34 |
SQL - THIRD Largest value
To retrieve the THIRD Largest value from the Amount column in the "Orders" Table.
Text Editor below has the SQL Query, click the "View Result" button, to see the result.
Select MIN(Amount) as ThirdLargest From Orders
Where Amount IN (
Select TOP 3 Amount from Orders
ORDER BY Amount Desc);
Note: The SUBQUERY fetches the top 3 Maximum values of the Amount column and that is used by the Main Query.
In the Main Query the MIN function is used to get the least value from it.
SQL in Text Editor: