| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
|||
|
Do You Know How to select the nth(for ex : 10th) largest number in a column without using max() function..
I am using orderid column from orders table in nortwind database for example SELECT top 1 * FROM(SELECT top 10 orderid FROM orders ORDER BY orderid DESC)a ORDER BY orderid ASCBy : Krishna Prasad J krishnaprasad.jk@gmail.com |
|
|||
SELECT * FROM tablename orderby salary LIMIT 1 offset 2use 3 for third highest 4 for 4th highest after offset sameerargade@gmail.com |
|
|||
|
Hi,
You can use the following: SELECT *Also, you can use the DENSE_RANK() functionality to get this done in a better way: SELECT * Thanks, vinay singh Sagarpur New Delhi, India email- vinay_1020@live.in |
|
|||
|
Quote:
SELECT quantity FROM trade a WHERE 2=(SELECT count(quantity) FROM trade b WHERE a.quantity<=b.quantity);-hello friend this query is called nested sub query this is the only way to find the values in given count order |
|
|||
|
You can use following query to find any highest from a table column values:
SELECT MIN(columnName) |
|
|||
|
Correlated query:
1. SELECT sal FROM emp e WHERE 1=(SELECT count(DISTINCT(sal)) FROM emp WHERE e.sal<sal);this gives the exact second heighest value 2. SELECT sal FROM emp e WHERE &(n-1)=(SELECT count(DISTINCT(sal)) FROM emp WHERE e.sal<sal);this gives the nth heighest value from atable k.lakshmi_narayana@yahoo.co.in |
|
|||
|
this is how you can simply do this
SELECT col_name FROM table_name WHERE col_name NOT IN (SELECT col_name FROM (SELECT col_name FROM table_name WHERE col_name IS NOT NULL ORDER BY col_name DESC) |
|
|||
|
you can use this and this is general you can find any highest value
SELECT min(sal) FROM (SELECT sal FROM emp WHERE sal IS NOT NULL ORDER BY sal DESC) WHERE rownum<=&rownum |
|
|||
SELECT salary FROM(Here 4 specifies Max salary at fourth position |
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to find out the 4th highest value from the column? | Anoj biradar | SQL - Questions and Answers | 3 | 12-05-2007 03:54 AM |
| How to find second highest value of a column in a table? | SQL? | jaheer | SQL - Questions and Answers | 9 | 07-24-2007 11:07 AM |
| how to find third highest record from table? | davinder singh | SQL - Questions and Answers | 3 | 12-19-2006 11:57 AM |