GeekInterview.com
Series: Subject: Topic:
Question: 53 of 190

Write a query to display employee records having same salary?

Asked by: kowmudiswarna | Member Since Sep-2007 | Asked on: Sep 13th, 2007

View all questions by kowmudiswarna   View all answers by kowmudiswarna

Showing Answers 1 - 14 of 14 Answers
Ashutosh Srivastava

Answered On : Sep 21st, 2007

select * from emp where sal in(
select sal from emp where rowid not in(
select max(rowid) from emp group by sal))

Yes  1 User has rated as useful.
  
Login to rate this answer.
vanigreat

Answered On : Jan 8th, 2008

View all answers by vanigreat


select a.empno,a.ename,a.sal from scott.emp a where a.sal in

(select sal from scott.emp group by sal having count(*)>1)

Yes  4 Users have rated as useful.
  
Login to rate this answer.

 hi..
select name,salary from emp e1,emp e2 where e1.esalary=e2.esalary

Yes  2 Users have rated as useful.
  
Login to rate this answer.

select e1.ename,e2.salary from emp e1.emp e2 where
e1.emp_id=e2.emp_id

  
Login to rate this answer.

SQL> select distinct e.name,e.salary from employe e, employe a
  2  where e.salary = a.salary and e.name != a.name;

NAME           SALARY
---------- ----------
MANI            10000
SELVAM          10000
SURAJ           10000
KAMAL           20000
RAMESH          20000
SARA            20000

6 rows selected.

Yes  4 Users have rated as useful.
  
Login to rate this answer.

This query display the same salary.

select * from emp
where sal in (select sal from emp
group by sal
having count(1)>1)



Plz let me know in case of any problem

Thanks
Sarath

  
Login to rate this answer.
Prabakaran

Answered On : Jul 27th, 2011

select * from emp where eid in (select eid from emp groupby emp.sal having count(*)>1)

  
Login to rate this answer.
vishnu

Answered On : Aug 7th, 2011

select e.ename,e.salary from emp e self join emp s on e.salary =s.salary

Yes  1 User has rated as useful.
  
Login to rate this answer.
jo

Answered On : Aug 9th, 2011

select ename,sal from emp where sal in(select sal from emp group by sal having count(sal)>=2)

  
Login to rate this answer.
fire_starter

Answered On : Oct 9th, 2011

View all answers by fire_starter

Hello,

try this:

select emp_id, name, salary, rank() over ( order by salary ) from employee;

  
Login to rate this answer.

select distinct D. Ename,D.SAL from EMP E,EMP D WHERE E.SAL = D.SAL AND E.ENAME <> D.ENAME;

  
Login to rate this answer.
honeyanubha

Answered On : Jun 22nd, 2012

View all answers by honeyanubha

I think the easiest way is to SELECT A.* FROM EMPLOYEE A, EMPLOYEE B WHERE A.SAL = B.SAl AND A.ROWID <> B.ROWID

Code
  1. SELECT A.* FROM EMPLOYEE A, EMPLOYEE B WHERE A.SAL = B.SAl AND A.ROWID <> B.ROWID

  
Login to rate this answer.
vikash kumar singh

Answered On : Aug 4th, 2012

Code
  1. SELECT eMployee_Id,First_Name,Last_Name,Salary FROM(SELECT Employee_Id,First_Name,Last_Name,Salary,Count(*) Over (Partition BY Salary ORDER BY Salary) Cnt
  2. FROM Employees) WHERE Cnt>=2;

  
Login to rate this answer.

Code
  1. SELECT e1.ename,e1.sal,count(*) person_having_same_sal FROM emp e1,emp e2 WHERE e1.sal=e2.sal GROUP BY e1.sal,e1.ename HAVING count(*)>1;

OR

Code
  1. SELECT * FROM emp WHERE sal IN (SELECT sal FROM emp GROUP BY sal HAVING count(*)>1);

OR

Code
  1. SELECT DISTINCT e1.ename,e1.sal FROM emp e1,emp e2 WHERE e1.sal=e2.sal AND e1.ename!=e2.ename;

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

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.