select DISTINCT(user),host from logins where ip in (
SELECT ip FROM logins group by ip HAVING COUNT(user) > 1)
This works fine.
select DISTINCT(user),host,time from logins where ip in (
SELECT ip FROM logins group by ip HAVING COUNT(user) > 1)
By adding the time column it no longer selects distinct users and returns duplicates. Why does it do that? It only seems to happen when I add integner fields (id and time for example).
The query basically pulls users from the logins table with conficting IPs. One user should not be pulled more than once.
DISTINCT isn’t a function it works for each row, time is not same for all distinct users, so you can not use distinct.
Use GROUP BY, and use Group functions (MAX,MIN,GROUP_CONCAT etc) for time Column.