MySQL - Select multiple lines with the same values ​​with one that must be different

advertisements

I have a table for IP addresses used and the associated userId. Now I know how I would select multiple entries of the same IP but how would I go about only selecting multiple entries WITH a different userId?


You can use conditional aggregation over each ip address and check to see if more than one user be associated with that ip address.

SELECT ip
FROM yourTable
GROUP BY ip
HAVING COUNT(DISTINCT userid) > 1    -- or a higher number if you want