Reputation: 7875
Given I have a database table with a column containing strings and a column containing booleans, how can I query to find if there are any rows that have the same value in the string column but different values in the boolean column?
For example, given the following:
| some_string_column | some_boolean_column|
| value1 | true |
| value1 | false |
| value2 | true |
| value2 | true |
I am interested in value1 because it has rows with both a true and a false.
Upvotes: 1
Views: 1559
Reputation: 62831
Just use a group by
clause:
select some_string_column
from some_table
group by some_string_column
having count(distinct some_boolean_column) > 1
Upvotes: 1
Reputation:
You can do it like this:
SELECT some_string_column
FROM YourTable
GROUP BY some_string_column
HAVING COUNT(DISTINCT some_boolean_column) > 1
Upvotes: 1