View all questions by lalit.eng.kumar
select min(sal) from emp where sal=(select sal from emp where sal<>MIN(SAL) ) ORselect min(sal) from emp where sal=(select sal from emp having sal<>MIN(SAL) ) May this will help you.I have not tested it in SQL and I am also not sure that the syntax is exactly right .may be you need to do same changes
select min(sal) from emp where sal=(select sal from emp where sal<>MIN(SAL) ) OR select min(sal) from emp where sal=(select sal from emp having sal<>MIN(SAL) ) May this will help you.I have not tested it in SQL and I am also not sure that the syntax is exactly right .may be you need to do same changes
SELECT a.Emp_Name,a.Emp_sal FROM employee a where 2=(SELECT count(distinct(b.Emp_sal)) FROM employee b WHERE a.Emp_sal<=b.Emp_sal)
dont make simple queries the big ones,try to use as simple as possible:-
select max(sal) from emp where sal<>(select max(sal) from emp )
dont use that that is for second highest salary
sel emp_no,rank(emp_no) from emp order by acct_no asc QUALIFY RANK(emp_no) =2
select min(sal) from emp where emp.empcode in(select top 2 empcode from emp order by sal desc)
Go with this query (use inMS SQL server database)
Let me know, it is right or wrong.
select min(salary) from emp where salary in ( select distinct top 2 salary from emp order by salary desc)
select salary ,empname from emptable order by(salary) limit 1,1;
SELECT esalary FROM emp ORDER BY `esalary ` ASC LIMIT 1,1
select max(salary) from dept where salary in(select distinct top 2 salary from dept order by salary)
Tested query. Change top 2 to top 3 for 3 rd lowest and so on.
select min(sal) from emp where sal>(select max(sal) from emp );
With t1 as (select firstnme, salary, rank()over(order by salary) as rank from employee)
select * from t1 where rank=2
Answered On : Jul 2nd, 2009
View all questions by sivagarlapati View all answers by sivagarlapati
select min(salary) from emp where salary!=(select min(salary) from emp)
Try this it's 100% true answer
SELECT * FROM ( SELECT rownum n, id, salary FROM (select id, salary from employees order by salary )) where n = 2
This works perfectly even if you can find any nth highest or lowest salary.
Try this
SELECT min(sal) FROM emp WHERE sal > (SELECT Min(sal) FROM emp)
Inner query returns lowest salary. Then get lowest salary excluding the first lowest salary.
select * from (select rownum rank,salary from (select distinct(salary) from employees order by salary asc)) where rank = &n;
Place whatever the number that you want in place of N.
select min(sal) from (select sal from employee where sal>(select min(sal) from employee))
SELECT TOP 1 Empname,Salary FROM (SELECT TOP 2 Empname,Salary FROM Employee ORDER BY Salary ASC) X ORDER BY Salary DESC
select * from scott.emp a where 2 = ( select count(distinct(b.sal)) from scott.emp b where a.sal>=b.sal)
Select e.salary from emp e
where 1= ( select count(*) from emp s
where s.salary<e.salary)
Answered On : Dec 28th, 2010
View all questions by pravesh28 View all answers by pravesh28
there r various query for this question
1 select min(salary)
from emp
where salary in ( select top 2 salary
from emp
order by salary desc);
SELECT * FROM
(SELECT
employee_id
,salary
,dense_rank() OVER ( ORDER BY salary) as ranking
FROM employees) a
WHERE a.ranking=2
select salary from emp_table order by salary asc limit 1,1;
select * from emp a where 2=(select count(distinct(b.sal))from emp b where a.sal>=b.sal)
Select * From (Select * From sample_count_ex Where salary < (Select salary From (Select * From sample_count_ex Order By 4 Desc) Where rownum = 1) Order By 4 Desc) Where rownum = 1;
First query Select * From sample_count_ex Order By 4 Desc gets salary in descending order as we r doing order by desc;
So (Select salary From (Select * From sample_count_ex Order By 4 Desc) Where rownum = 1) gets Highest salary in that table
and (Select * From sample_count_ex Where salary < (Select salary From (Select * From sample_count_ex Order By 4 Desc) Where rownum = 1) Order By 4 Desc) gets Second highest Salary
and since rownum= 1
it returns only Second highest salary every time
select min(salary) from emp_table<>(select min(salary) from emp_table
);
Sorry Previous is not good but this one seems good.
select min(sal) from emp where sal>(select min(sal) from emp)
select sal from(select sal,rank() over (order by sal asc) as rank from emp ) where rank=2;
Select Salary From Empwhere Salary In(Select Salary From Emporder By Salary Asc where Rownum = 2);
SELECT sal FROM
Select Sal from
(Select sal, rank() over(order by sal desc)rnk
from employee)temp where rnk=2
Answered On : Aug 17th, 2011
-- Find Second lowest Salary ----
SELECT DISTINCT(a.sal) FROM emp a WHERE 2 = ( SELECT DISTINCT(COUNT(b.sal)) FROM emp b
WHERE a.sal >= b.sal )
Answered On : Aug 19th, 2011
Code
SELECT * FROM (SELECT * FROM (SELECT DISTINCT sal FROM emp ORDER BY sal DESC) WHERE ROWNUM < n+1 ORDER BY sal) WHERE rownum<2
Code
SELECT MIN(SAL) FROM EMPLOYEE WHERE SAL>(SELECT MIN(SAL) FROM EMPLOYEE)
Answered On : Mar 22nd, 2012
select max(sal) from emp where sal<>(select max(sal) from emp);
Answered On : Apr 16th, 2012
Code
SELECT * FROM emp a WHERE (&n-1) =(SELECT count(UNIQUE sal) FROM emp b WHERE a.sal>b.sal) FOR nth minimum salary SELECT * FROM emp a WHERE (&n-1) =(SELECT count(UNIQUE sal) FROM emp b WHERE a.sal<b.sal) FOR nth maximum salary
Answered On : May 13th, 2012
View all questions by Gunjan David View all answers by Gunjan David
Ypu need to know MR. SQL that you cant use = operator with rownum ....
Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.
