Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find all IP columns that occures with different Logins columns

I’ve got Postgres table with text columns – LOGIN and IP. I need to find all matches where IP occured with only different LOGIN columns.

Here is an example of input data:

LOGIN    IP
A        127.0.0.1
A        127.0.0.1
B        127.0.0.2
C        127.0.0.1 // same as A
D        127.0.0.3
D        127.0.0.3
E        127.0.0.2 // same as B

Here is what I want in output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

LOGIN    IP
A        127.0.0.1
C        127.0.0.1
B        127.0.0.2
E        127.0.0.2

Can I do it with one query?

>Solution :

It looks like you need exists

select distinct Login, IP
from t
where exists (
    select * from t t2
    where t2.ip = t.ip and t2.login != t.login
)
order by IP
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading