I hope someone can help with this!
I’ve used the following query to count the distinct values in column2 and column3 and filter the results:
SELECT
column1,
COUNT(DISTINCT(column2)),
COUNT(DISTINCT(column3))
FROM table1
GROUP BY column1
HAVING COUNT(DISTINCT(column2)) > 1
OR COUNT(DISTINCT(column3)) > 1
The output looks something like this:
| column1 | column2 | column3 |
| -------- | -------- | |
| abcd | 1 | 2 |
| efgh | 2 | 2 |
| ijkl | 2 | 1 |
I would now like to see what these distinct values of column2 and column3 associated with each value of column1 are. So, abcd will have one distinct value from column1 but two distinct values from column2- so I’m expecting the output to have two rows for abcd, with the value in column1 repeating, and two different values in column2
Does anyone know how to go about this?
2
Answers
This sql will show you all individual values and how often they exist:
This example is only for column2, but you can extend it easy to more columns.
Let a subquery return the column1 values having more than one distinct column2 or column3 values.