WITH film_size AS (
SELECT film_id,
COUNT(*) AS actors_cnt
FROM film_actor
GROUP BY film_id
ORDER BY actors_cnt DESC
LIMIT 1
)
SELECT title
FROM film
WHERE film_id IN (
SELECT film_id
FROM film_size
);
Explanation
This query retrieves the title of the movie that has the most actors in it.
First, it creates a temporary table called "film_size" using a subquery that counts the number of actors in each movie and orders them by the count in descending order. It then selects the movie with the highest actor count using the LIMIT 1 clause.
Finally, it selects the title of the movie from the "film" table that matches the movie with the highest actor count using a WHERE clause that filters by the film_id column in the "film_size" table.
Copied
Last Submission
postgres
No submission yet for this engine. Run and submit your query to save it here.
Copied
Expected results
Submit a query to compare against expected output.