Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all rows which have same value in some column

I am new to sql so please be kind.

Assume i must display all the employee_ids which have the same phone number(Both columns are in the same table)

How am i to proceed on this problem inner join or something.

like image 488
Win Coder Avatar asked Sep 16 '13 18:09

Win Coder


1 Answers

SELECT * FROM employees e1, employees e2  WHERE e1.phoneNumber = e2.phoneNumber  AND e1.id != e2.id; 

Update : for better performance and faster query its good to add e1 before *

SELECT e1.* FROM employees e1, employees e2  WHERE e1.phoneNumber = e2.phoneNumber  AND e1.id != e2.id; 
like image 112
agusluc Avatar answered Oct 01 '22 02:10

agusluc