As much as I understand you want to get number of films for each actors
.
I think you have actor
, film
and film_actor
tables and film_actor
table has link between actor
and film
tables. So;
You don't need to JOIN
second time the film_actor table for your purpose. Also, You have missed to link between film
and film_actor
tables.
GROUP BY
was wrong. You need to put not aggregated columns to the GROUP BY
(only if you used them in SELECT
).
If you can provide your table structure we can answer better. With the information you provide I believe this following query can help you :
SELECT concat(a.last_name, ', ',a.first_name) as Actor
, count(fa.actor_id) as Num_Films
, f.title as Movie
FROM actor as a
INNER JOIN film_actor fa ON a.actor_id = fa.actor_id
INNER JOIN film f ON fa.film_id = f.film_id
GROUP BY concat(a.last_name, ', ',a.first_name),f.title
ORDER BY a.last_name;
EDIT : If you want to get number of movies for each actors you shouldn't add film.title to the select, otherwise you will get 1 as number of films for each line. I excluded the film information from the query :
SELECT concat(a.last_name, ', ',a.first_name) as Actor
, count(fa.actor_id) as Num_Films
--, f.title as Movie
FROM actor as a
INNER JOIN film_actor fa ON a.actor_id = fa.actor_id
--INNER JOIN film f ON fa.film_id = f.film_id
GROUP BY concat(a.last_name, ', ',a.first_name)
--,f.title
ORDER BY a.last_name;