比较数据库项以查找重复项

i have no code as of yet because i have never written such a query. my company's e-commerce website offers 20% off the first purchase. we are finding sneaky people create multiple accounts to take advantage. at this point when creating an account, it only checks for a matching email.

what the boss wants is whenever he logs into the admin area a query runs and displays any accounts that have the same firstname and last name, as well as other items. the only way i can think to do it is to select all users, and loop through them all searching for matches. i would think this could be done with one query though. here is an example of what i want:

$res=$mysqli->query("SELECT * from users");
while($user = $res->fetch_array()){

    $res2=$mysqli->query("SELECT * FROM users WHERE firstname='".$user->firstname."' 
                                OR lastname='".$user->lastname."' .... ");
     while($user2 = $res2->fetch_array()){
        print $user->id . " matches " . $user2->id;
     }

}

can this be done with one query, and if so please proive an example, or link. i appreciate any help

Join on the same table:

SELECT * FROM users u1 LEFT JOIN users u2 ON (u1.FirstName = u2.FirstName) 
    WHERE u1.Id != u2.Id;

Something like this might give you an idea.

select field, GROUP_CONCAT(id SEPARATOR ',') from table group by field having count(field) > 2;