How to find nth highest value of a MySQL column?
Answers
Answered by
1
SELECT * FROM `employees` e1 WHERE (N-1) = (SELECT COUNT(DISTINCT(salary)) FROM `employees` e2 WHERE e1.salary < e2.salary ); N=2 for second highest N=3 for third highest and so on. This query will give second highest salary of the duplicate records as well.
Answered by
0
mysql> SHOW COLUMNS FROM mytable FROM mydb; mysql> SHOW COLUMNS FROM mydb.mytable; SHOW COLUMNS displays the following values for each table column: Field indicates the column name. ... If Key is UNI , the column is the first column of a unique-valued index that cannot contain NULL values.
Similar questions