CREATE TABLE EMPLOYEE (
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
SALARY REAL
)
INSERT INTO COMPANY (ID, NAME, SALARY,)
VALUES (2, 'Allen', 25000);
INSERT INTO EMPLOYEE (ID, NAME, SALARY)
VALUES (1, 'Rohit', 50000);
INSERT INTO EMPLOYEE (ID, NAME, SALARY)
VALUES (3, 'Krishna', 70000);
INSERT INTO EMPLOYEE (ID, NAME, SALARY)
VALUES (4, 'Ram', 80000);
INSERT INTO EMPLOYEE (ID, NAME, SALARY)
VALUES (5, 'Ganesh', 90000);
SELECT * FROM EMPLOYEE
Here 3rd highest salary is 70000.
-- Step 1 - Let's see all salaries
-- Step 1 - Let's see all salaries
select salary from employee order by salary desc limit 3
--Step 4 - Arrange the result in ascending order and limit to 1 to get the 3rd highest salary
select name,salary from (select name,salary from employee order by salary desc limit 3) A order by salary limit 1
Here A is alias for table

No comments:
Post a Comment