MySQL Select rows with the same column value

I need to get rows that have the same column value from the following table, I tried it as follows, but it gives me only one row.

select *
from employee e
group by e.empsalary
having count(e.empsalary) > 1

Employee table

enter image description here

Please suggest me a way.

+4
source share
4 answers

You must accomplish this by attaching the table to yourself:

SELECT
    a.*
FROM
    employee a
    JOIN employee b
        ON a.empsalary = b.empsalary
        AND a.empid != b.empid
+8
source

Use an internal join to join your advertised request.

select A.* from employee A
inner join (
  select empsalary
  from employee 
  group by empsalary
  having count(*) > 1
) B ON A.empsalary = B.empsalary
+3
source

-

SELECT * FROM employee a
WHERE EXISTS (
    SELECT 1 FROM employee b
    WHERE a.empsalary = b.empsalary
    AND a.empid <> b.empid
);

- http://sqlfiddle.com/#!2/d75d9/4

+2
select * from employee where empsalary IN(select empsalary from employee  group by empsalary having count(empsalary ) > 1)

This.It 2 , .

: http://sqlfiddle.com/#!2/d75d9/6

+2

Source: https://habr.com/ru/post/1529925/


All Articles