I\'m working on a problem in my database. I\'m trying to find the users who are using multiple accounts. I have a list of user IDs and used IP addresses, like this:
Taking the data from your example:
+--------+---------+
| userid | address |
+--------+---------+
| 1 | 12 |
| 5 | 12 |
| 1 | 13 |
| 2 | 23 |
| 9 | 23 |
| 2 | 56 |
| 4 | 56 |
+--------+---------+
for a table defined as
CREATE TABLE table_27620030 (
userid INTEGER,
address INTEGER
);
the following query will list all userids that share the same address (and the address):
SELECT address, GROUP_CONCAT(userid) userids
FROM table_27620030
GROUP BY address
HAVING COUNT(DISTINCT userid) > 1
ORDER BY address
;
result:
+---------+---------+
| address | userids |
+---------+---------+
| 12 | 1,5 |
| 23 | 2,9 |
| 56 | 2,4 |
+---------+---------+