Thursday , April 25 2024
Home / MySql

MySql

Get the rank of a user in a score table

Below is Scores Table data and structure Id Name score 1 Ram 90 2 Shyam 85 3 Dhanshyam 95 4 Sita 65 5 Geeta 98 6 Radha 45   SELECT id, name, score, FIND_IN_SET( score, ( SELECT GROUP_CONCAT( score ORDER BY score DESC ) FROM scores ) ) AS rank …

Read More »

How to get second-highest salary of employees in a table

Method 1) Below query can be used to find the nth maximum value, just replace 1 from nth number SELECT * FROM `emp` e1 where 1 = (select count(distinct(salary)) from emp e2 where e2.salary>e1.salary) Method 2) select * from emp where salary = (select max(salary) from emp where salary < …

Read More »