Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the name of the employees, whose names are same but salary are different

Tags:

sql

I have an 'employee' table with

create table employee
(
  e_number int,
  e_name varchar(20),
  salary money,
  hire_date date
)

Now I want to display only the name of the employees who have the same name but different salary.

I tried select e_name,count(*) from employee group by e_name having count(*)>1; but cannot combine it with "the same salary" section. Any help?

like image 580
Srijit B Avatar asked Dec 05 '25 04:12

Srijit B


1 Answers

This assumes that you want the names of both of the people listed:

SELECT e1.e_name
FROM employee e1, employee e2
WHERE e1.e_name = e2.e_name
AND e1.salary <> e2.salary;

If you only want each name listed once, you would use a SELECT DISTINCT instead of the SELECT.

like image 101
Michael Davis Avatar answered Dec 07 '25 20:12

Michael Davis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!