In mysql i will show how to get mysql second highest salary given below example step by step.

Step : 1 – Create Table

CREATE TABLE employee (
id int(11) DEFAULT NULL,
name varchar(40) DEFAULT NULL,
salary int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Step : 2 – Insert record in employee table

INSERT INTO employee (id, name, salary) VALUES
(1, ‘Mike’, 3000),
(2, ‘John’, 4000),
(3, ‘Shane’, 3000),
(4, ‘Biden’, 5000),
(5, ‘Bravo’, 7000);

Step : 3

Below I write the query to get second highest salary of employee

First Query : Select salary from employee order by salary desc limit 1,1;

Second Query : Select max(salary) from employee where salary <> (Select max(salary) from employee);

Third Query : Select salary from employee a where 1 = (select count(1) from employee b where b.salary>a.salary)

Related Topic :
Physics FormulasChemistry Formulas
Maths FormulasComputer Interview Questions and Answers for Freshers & Experienced
What is LibreOffice? LibreOffice Impress Features ?LibreOffice Impress CCC Questions and Answer in Hindi 2022
CCC LibreOffice Calc Paper Questions with AnswersCCC NIELIT Quiz 2022
Interview Questions and Answers for ExperienceInterview Questions and Answers for Freshers
MCQ 
[social_share_button themes='theme1']

Leave a Comment