Skip to content
Advertisement

Find rows with column equal and other different

I need to extract all rows that have same column value (wihout duplicates) and the other column value with different value.

I have problems when I’m trying to get null values since the sentence “having count (distinct)” not include null values.

My example (https://dbfiddle.uk/?rdbms=postgres_9.4&fiddle=ae1db1de07f9a54171c5121b49112273) :

It gives me:

I need also

Advertisement

Answer

Since you are using postgres the syntax is slightly different

https://dbfiddle.uk/?rdbms=postgres_9.4&fiddle=27b4cf8e44d7a088331f70ba2b519644

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