GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Database  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 129 of 139    Print  
Find second lowest salary from emp table
display the second lowest salary from emp table without using min & all


  
Total Answers and Comments: 14 Last Update: July 02, 2009     Asked by: lalit.eng.kumar 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: ashjain78
 
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)

Above answer was rated as good by the following members:
rajendrareddyv, darmismarcelo, luzaolai
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
May 07, 2008 14:39:22   #1  
aleeza Member Since: May 2008   Contribution: 2    

RE: Find second lowest salary from emp table
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
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 3Overall Rating: -3    
May 09, 2008 11:56:59   #2  
aleeza Member Since: May 2008   Contribution: 2    

RE:

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


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
May 22, 2008 03:19:54   #3  
ashjain78 Member Since: May 2008   Contribution: 1    

RE: Find second lowest salary from emp table
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)
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
June 02, 2008 06:06:05   #4  
priiti_bangarwa26 Member Since: June 2008   Contribution: 3    

RE: Find second lowest salary from emp table
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 )


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
June 02, 2008 06:08:41   #5  
priiti_bangarwa26 Member Since: June 2008   Contribution: 3    

RE: Find second lowest salary from emp table
dont use that that is for second highest salary
 
Is this answer useful? Yes | No
June 02, 2008 06:37:05   #6  
priiti_bangarwa26 Member Since: June 2008   Contribution: 3    

RE: Find second lowest salary from emp table
sel emp_no rank(emp_no) from emp order by acct_no asc QUALIFY RANK(emp_no) 2
 
Is this answer useful? Yes | No
June 06, 2008 16:32:21   #7  
anantdeshmukh001 Member Since: May 2008   Contribution: 1    

RE: Find second lowest salary from emp table

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.


 
Is this answer useful? Yes | No
July 11, 2008 03:07:30   #8  
ashwin890 Member Since: July 2008   Contribution: 2    

RE: Find second lowest salary from emp table
select min(salary) from emp where salary in ( select distinct top 2 salary from emp order by salary desc)
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 17, 2008 23:46:22   #9  
anu1985 Member Since: May 2008   Contribution: 11    

RE: Find second lowest salary from emp table
select salary empname from emptable order by(salary) limit 1 1;
 
Is this answer useful? Yes | No
July 21, 2008 02:08:19   #10  
maartha Member Since: July 2008   Contribution: 1    

RE: Find second lowest salary from emp table
SELECT esalary FROM emp ORDER BY `esalary ` ASC LIMIT 1 1

 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape