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

Win Coder picture Win Coder · Sep 16, 2013 · Viewed 134.5k times · Source

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.

Answer

agusluc picture agusluc · Nov 13, 2014
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;