Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Select the rows having same column value

Tags:

sql

mysql

I need to obtain the rows which having same column value from the following table, I tried it the following way, but it gives me a single row only.

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

Table employee

enter image description here

Please suggest me a way.

like image 527
Dilukshan Mahendra Avatar asked Dec 07 '22 03:12

Dilukshan Mahendra


1 Answers

You should be able to accomplish this by joining the table to itself:

SELECT
    a.*
FROM
    employee a
    JOIN employee b
        ON a.empsalary = b.empsalary
        AND a.empid != b.empid
like image 134
newfurniturey Avatar answered Dec 20 '22 20:12

newfurniturey