There are two ways to solve your situation:
- If you need all attributes (zip code, city and ip) to be different:
SELECT * FROM tabela_login tab1 INNER JOIN tabela_login tab2 on (tab1.email = tab2.email) AND (tab1.cep <> tab2.cep AND tab1.cidade <> tab2.cidade AND tab1.ip <> tab2.ip)
- If you need at least one of the attributes (cep, city and ip) to be different:
SELECT * FROM tabela_login tab1 INNER JOIN tabela_login tab2 on (tab1.email = tab2.email) AND (tab1.cep <> tab2.cep OR tab1.cidade <> tab2.cidade OR tab1.ip <> tab2.ip)
Because of performance in the query I would advise to remove the city attribute from the conditions, since the zip code already points to a certain city as well, so it is comparing information which one is contained in the other (zip code city).
tried to query? If yes include in the question
– Claudio Lopes
I have logic in my head but I don’t know how to write the query, maybe some command I don’t know.
– Elvis
Search for "group by" and "having", "subselects", see also "Primary key" "Unique key".
– Motta
Make sure you answer:
SELECT * FROM sua_tabela a INNER JOIN sua_tabela b ON (a.email = b.email AND (a.cep <> b.cep OR a.cidade <> b.cidade OR a.ip <> b.ip));
.– anonimo
worked perfectly very obg!!!
– Elvis