I'm trying to understand how mysql queries work with and without GROUP BY.
Imagine I have a table of FILM_ACTORS, where each ACTOR_ID has a corresponding FILM_ID. So the same actor participates in N different movies.
I want to select the actors that participate 20 movies:
SELECT actor_id FROM film_actor GROUP BY actor_id HAVING COUNT(film_id) = 20;
This query works and returns the actor_ids that participate in 20 movies. But what if I just did:
SELECT actor_id FROM film_actor HAVING COUNT(film_id) = 20;
Why does this query only returns values if I equal it to the SIZE of film_actor table (5463):
SELECT actor_id FROM film_actor HAVING COUNT(film_id) = 5463;
In this case it returns me actor_id = 1. Why? Is it selecting film_ids without considering the corresponding actor_ids?