Home > OS >  How to list non-unique combinations of two columns with PostGreSQL?
How to list non-unique combinations of two columns with PostGreSQL?

Time:10-26

How to list non-unique combinations of two columns?

And get a result like this:

col A | col B   | count
foo   | bar     | 3
abc   | hello   | 2
def   | world   | 4

If this combination only exists once, then it's not listed:

bob   | alice     | 1

CodePudding user response:

SELECT col_A, col_B, count(*) AS count
FROM your_table
GROUP BY col_A, col_B
HAVING count(*) > 1
  • Related