Skip to content
Advertisement

Get movies that have categories

I have associative table movies and their categories.

How can i get movies that have category 1 and 2?

Result:

Advertisement

Answer

Do GROUP BY. Use HAVING with COUNT DISTINCT to make sure both 1 and 2 are there.

Just for fun, you can also do a self join:

Or, use INTERSECT:

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