If I have this table:
+------+-------+---------------+--------+-----------------+------------+-----------+----------------+------+------+--------+------------+------------+
| type | class | username | userid | userip | usermobile | useremail | daysleft| pin1 | pin2 | pin3 | active | schoolname | schoolsite |
+------+-------+---------------+--------+-----------------+------------+-----------+----------------+------+------+--------+------------+------------+
| B | A | sebbetest | 1000 | 123.123.123.123 | none | none | 50| 0 | 0 | 0 | Y | none | none |
| A | A | stackowerflow | 5355 | 123.123.123.123 | none | none | 50| 0 | 0 | 0 | Y | none | haha |
| C | A | good | 4223 | 123.123.123.124 | none | none | 50| 0 | 0 | 0 | Y | none | haha |
| A | A | tester | 6353 | 123.123.123.125 | none | none | 50| 0 | 0 | 0 | Y | none | haha |
| B | A | admin | 3453 | 123.123.123.125 | none | none | 50| 0 | 0 | 0 | Y | none | eeee |
| A | A | sebastian | 1342 | 123.123.123.126 | none | none | 50| 0 | 0 | 0 | Y | none | eeee |
| C | A | username | 6456 | 123.123.123.125 | none | none | 50| 0 | 0 | 0 | Y | none | woooooow |
+------+-------+---------------+--------+-----------------+------------+-----------+----------------+------+------+--------+------------+------------+
As you see, the user "good" with the IP "123.123.123.124" AND user "sebastian" with IP "123.123.123.126" has no "companions", no other users on the same IP.
The user "sebbetest" has a companion "stackowerflow".
The user "tester" has 2 companions: "admin" and "username".
Now I want to delete these users that lack companions. How I do? For atomic reasons and to prevent concurrent access from munging the database, I would want to delete all "non-companion" users in a single expression of SQL.
I tried with: DELETE FROM lan WHERE COUNT(userip) = 1;
got this: ERROR 1111 (HY000): Invalid use of group function
No rows are duplicates. If there is a need to check if a entry is unique regardless of IP, (type, userid) is unique.
In other words, if IP is unique in a row, delete it.