Skip to content
Advertisement

Find SQL table rows where there are multiple different values

I want to be able to filter out groups where the values aren’t the same. When doing the query:

We get the following results:

The goal: Update the query so that it yields:

In other words, find the categories where the values are different from the others in that same category.

I have tried many different methods of joining, grouping and so on, to no avail.

I know it can be done with multiple queries and then filter with a little bit of logic, but this is not the goal.

Advertisement

Answer

You can use aggregation:

You have left the FROM clause out of your query. But as written, you don’t need a JOIN at all. The object table is sufficient — because you are only fetching the category id.

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