pardipbhatti8791
2/16/2016 - 7:23 AM

How to get second hieghest salary in mysql ?

How to get second hieghest salary in mysql ?

<!-- Create Table Name Employee -->
create table employee(id int primary key auto_increment NOT NULL, name varchar(255), sal varchar(255));
insert into employee(name, salary)values('Pardip', '35000');
insert into employee(name, salary)values('Gagan', '34000');
insert into employee(name, salary)values('Ajay', '9500');
insert into employee(name, salary)values('Sunil', '35000');
insert into employee(name, salary)values('Gurvir', '10000');
insert into employee(name, salary)values('Hardeep', '5000');

<!-- Trigger Below Mention Query -->

<!-- DESC limit 2,1 Here 2 is index and 1 is limit. Means Query will start from second row and limit will be one -->
<?php 

  SELECT DISTINCT(column_name) FROM table_name ORDER BY column_name DESC limit 2,1;

?>
<!-- Or You Can Use Below Mention Code -->
<?php

  SELECT name, salary
  FROM employee
  WHERE salary = (SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee));

?>