September 1st, 2002, 09:31 AM
How do u select records where two or more fields are the same?
Need some help with a little SQL code.
I have a table with fields:
I want to select all records where there are two or more equal passwords. Is it possible?
(in case it may help Im using MySQL)
September 1st, 2002, 02:28 PM
You can always join a table to itself for comparison purposes. This code assumes that your table is called mytable and that id is unique.
SELECT DISTINCT t1.id, t1.name, t1.password
FROM mytable t1, mytable t2
WHERE t1.password = t2.password and t1.id != t2.id
September 1st, 2002, 02:43 PM
That didnt seem to work for me.
I figured our part of it.
SELECT password FROM table
GROUP BY password HAVING count( * ) > 1
But that returns all passwords which are used more than once, which ispartly what I want. Im having to then make a query for each of those passwords returned by the above to get the rest of the table information.
Its slow. There is another method, using "In" (Im guessing a query in a query), but MySQL doesnt seem to want to support it.