how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / ashish damohiya
Answer :
Select max(salary) from Emp_Table where max(salary) not in
(Select max(Salary) from Emp_Table)
this sufficient answer.
but there change the format of question that
How to find the second highest salary of each employee form
emp table ?
Answer :
with cte as (
select rank() over(order by emp_name) rank1 , ROW_NUMBER()
OVER(partition by emp_name ORDER BY basic desc) row,
emp_name, basic from emp_master)
select * from cte where row =2 or rank1 in ( select rank1
from cte group by rank1 having count(rank1)=1)
there i am used the MS SQL Server 2005.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / chaitanya pathak
select max(salary) from employee
where salary<(select max(salary) from employee)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / bharath reddy
These qeries give you second higest salary
select e.sal from emp e,emp d where d.sal>e.sal
group by e.sal
having count(e.sal)=2
;
SAL
-----
3000
(or)
select distinct e.sal from emp e where (select count(sal)
from emp d where d.sal>e.sal)=1;
SAL
-----
3000
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / anandaraj
This below query is used to get the name and salary of
second highest salary person. Its work great.
select Name, Salary from table_3 where salary = (select max
(salary) from table_3 where salary < (select max(salary)
from table_3 )).
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / raju
select top 1 sal from emp
where sal not in (select top 1 sal from emp order by sal
desc ) order by sal desc
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / jigar r gor
Select sal from emp where sal < (select max(sal)from emp)
and rownum < 2 order by sal desc
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sagar padekar
select * from bill_gen
where total_payable< (select max(total_payable) from
bill_gen) order by total_payable desc limit 1;
hey please refer total_payable as salary amount
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / shiva
select salary from table_name where salary <(select salary
from table_name);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / yash goyal
Select slary from
(select salary from empolyees
order by salary desc
where rownum<=&no.)
order by salary Asc
where rownum=1;
| Is This Answer Correct ? | 0 Yes | 0 No |
Mention what does plvtab enables you to do when you showthe contents of pl/sql tables?
What are dml commands?
When we can declare a column as Unique and Not Null both at the same time. What is the use pf Primary Key then?
2 Answers Accenture, Unisoft Infotech,
What is number function in sql?
What do you mean by “trigger” in sql?
cursor types? explain with example programs?
What is thread join () in threading?
what tools available for managing mysql server? : Sql dba
Given two tables Student(SID, Name, Course) and Level(SID, level) write the SQL statement to get the name and SID of the student who are taking course = 3 and at freshman level.
define a variable representing the expression used to calculate on emps total annual remuneration.use the variable in a statement which finds all emps who can earn 30000 a year or more.
what is the command for user data type?
What are the two different parts of the pl/sql packages?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)