Skip to content
Advertisement

Finding pairs of keys with the same values postgresql

I want to write a SQL query that find the paires of keys that have the same values. Each key can have multible values.

Example of table:

So in this example the only pair would be (a,c) because they both have the keys 1 and 2, while b only has the key 1.

To solve this problem I was thinking something like this

Where [id] could be a, b or c. If that query returns no rows then they have the same values. But i’m stuck after that.

Advertisement

Answer

I am thinking two levels of aggregation:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement