Just for an example. How can I query my db to find two users who might be using the same phone number? I'm not inputting a specific number but I want to find all instances phone numbers that are being used more than once in the user table.
views:
40answers:
2
+4
A:
SELECT ... FROM users u1 JOIN users u2
ON u1.user_id <> u2.user_id AND u1.phone_number = u2.phone_number;
Bill Karwin
2010-08-18 23:07:36
A:
You would use two tables of the same table with aliasses like:
select a.name, b.name
from mytable a join mytable b on a.phonenumber = b.phonenumber
where a.name <> b.name
Frank
2010-08-18 23:08:35