Write a query to display employee records having same salary?

Questions by kowmudiswarna   answers by kowmudiswarna

Showing Answers 1 - 67 of 67 Answers

Ashutosh Srivastava

  • 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))

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.

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

  Was this answer useful?  Yes

Prabakaran

  • Jul 27th, 2011
 

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

  Was this answer useful?  Yes

vishnu

  • Aug 7th, 2011
 

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

jo

  • Aug 9th, 2011
 

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

  Was this answer useful?  Yes

honeyanubha

  • Jun 22nd, 2012
 

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

  Was this answer useful?  Yes

vikash kumar singh

  • 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;

  Was this answer useful?  Yes

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;

  Was this answer useful?  Yes

Revel

  • Aug 24th, 2016
 

Why we used count(1)>1 here? Can you explain please?

  Was this answer useful?  Yes

amaresh

  • Mar 16th, 2017
 

Assuming your question is why the guy has used count(*)>1, the reason is: First we need to group by all the values, when you group by the result set is all the values which are having same values w.r.to that coulmn will be under single group. Suppose two employees having same salary as 5000, then under 5000 group we have two employees and in order to find if the employees are more than one or not we have to use count(*)>1 ...simple ...enjoy

  Was this answer useful?  Yes

Pinky

  • May 31st, 2017
 

SELECT * FROM EMPLOYEE E1, EMPLOYEE E2 WHERE E.SAL = E2.SAL AND E1.EMP_ID <> E2.EMP_ID

  Was this answer useful?  Yes

Ranaj Kumar Parida

  • Jul 31st, 2017
 

SELECT ENAME,JOB SAL,DEPTNO FROM EMP
WHERE SAL IN
(
SELECT SAL FROM EMP
GROUP BY SAL
HAVING COUNT(*)>1
);

  Was this answer useful?  Yes

amit

  • Oct 20th, 2017
 

SELECT SAL,listagg(ename,,) within group(order by ename) same_sal from t1
group by sal
having count(ename)>1;

  Was this answer useful?  Yes

Asish

  • Jan 7th, 2018
 

Select e.* From employee e, employee f
Where e.employee_id != f.employee_id
And e.sal = f.sal

  Was this answer useful?  Yes

RANAJ KUMAR PARIDA

  • Feb 27th, 2018
 

SELECT E1.* FROM EMP E1
WHERE SAL
IN
(
SELECT SAL FROM EMP
GROUP BY SAL
HAVING COUNT(*) > 1
);

  Was this answer useful?  Yes

Ekansh

  • Jul 12th, 2022
 

just add the ; in the end of quest :)

  Was this answer useful?  Yes

Vamsikrishna Sudanagunta

  • Nov 16th, 2022
 

Print first names and the last names of the artists who had zero sales or no sales?

  Was this answer useful?  Yes

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions