how to calcuate the second highest salary of he employee
Answers were Sorted based on User's Feedback
Answer / neetika vardhan
SELECT MAX(sal)
FROM EMP WHERE sal NOT IN (SELECT MAX(sal) FROM emp)
| Is This Answer Correct ? | 42 Yes | 3 No |
Answer / ramya p
SELECT DISTINCT (sal),deptno FROM emp a
WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM emp b
WHERE a.sal<=b.sal)
N is the Nth highest salary you want to print. In this case
N=2
| Is This Answer Correct ? | 7 Yes | 1 No |
Answer / hari krishna j
SELECT A.SAL FROM EMP_TAB A
WHERE 1=(SELECT COUNT(*) FROM EMP_TAB B
WHERE B.SAL > A.SAL)
Change value of 1 if
0 - First heighest sal
1 - Second " "
2 - Third heighest sal
.
.
.
| Is This Answer Correct ? | 5 Yes | 0 No |
Answer / udhayakumar
select salary from (select salary from emp order by salary
desc) where rownum=2;
| Is This Answer Correct ? | 3 Yes | 2 No |
Answer / eshwer
Try this
select * from (SELECT empno,sal, DENSE_RANK() OVER (ORDER BY sal desc) AS SalRnk
FROM scott.emp) where salrnk=2;
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / vinayak jamdar
Select top 1 empid,salary from (select distinct top 2
empid,salary from emp order by salary desc)a order by salary
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sunilpanghal
select rownum as rowid,salary from (salary from employees
oderby salary )where rownum <2
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sachin s. patil
SELECT * FROM
(SELECT ROWNUM DD, M.* FROM
(SELECT SAL FROM EMP order by sal desc )M)
WHERE DD=2
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / lalit
select name, sal from (select name,sal from emp where sal<(select max(sal) from emp) order by sal desc)where rownum=1;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sachin s. patil
SELECT SAL FROM
(SELECT ROWNUM DD, M.* FROM
(SELECT SAL FROM EMP order by sal desc )M)
WHERE DD=2/***HERE U CAN ADD ANY NUMBER (WHERE I PUT 2)
, U WILL GET HEIGHEST SALARY THAT POSITION *******/
| Is This Answer Correct ? | 0 Yes | 1 No |
What is the difference between inner join and left join?
what is check constraint? : Sql dba
Which is better join or inner query?
what is sql optimization
Are null values same as that of zero or a blank space?
What does plvtab enables you to do when you showthe contents of pl/sql tables?
Is it possible to use Transaction control Statements such a ROLLBACK or COMMIT in Database Trigger ? Why ?
How do you write a subquery?
diff b/w function and procedure?
What is a primary key? Explain
what are date and time functions in mysql? : Sql dba
1. is it possible to use the cursor atttibutes (%found ,% rowcount , %isopen , %notfound ) to our user defined cursor names ....... cursor cursor_name is select * from scott.emp if you use... cursor_name%found , %rowcount ,%isopen,%notfound...will it work... -------------------------- 2.what is the difference between the varray and index by table .. -------- 3. type type_name is table of number(8,3) index by binary_integer; identifier_name type_name; first , last , prior , next ,trim are the methods we can use it for the above type...simillary is there any way to apply for cursors... with thanks and regards..sarao...
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)