mysql - Get all the IP addresses for an all email addresses in a table -


lets have table named record , has 3 fields

id email ip

situation

we have find out of email addresses have used more 2 ip addresses , ip addresses. if count use

select email,count(distinct ip) c record group email having(c>2) 

but need see ip addresses. expected output like

 email1@example.com  192.168.0.1 email1@example.com  192.168.0.2 email1@example.com  192.168.0.3 email1@example.com  192.168.0.4 email1@example.com  192.168.0.5  ...etc...  email2@example.com  192.168.1.3 email2@example.com  192.168.1.4 email2@example.com  192.168.1.5 

any suggestion how join table , desired output without killing mysql 1 million records?

note: please note ip stored int , indexed. won't need converting ip string representation, can ignored practical answers question.

based on reply @meherzad, returning unique ip addresses:-

select     a.email,     a.ipaddress,    b.cnt    (select email, count(distinct ip) cnt    record     group email     having(c>2))b inner join    (select distinct email, ip    record) on    a.email = b.email; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -