Your query should do what you want, but you need to fix the limit
clause. If youw want the one actor with most movies, then you need limit 1
rather than limit 2, 1
. The concat()
in the select
clause also needs to be fixed - you want the space between the names, not before them.
Another option is to use an aggregate subquery for sorting, which avoids aggregation in the outer query:
select concat(a.first_name, ' ', a.last_name) as full_name
from actor a
order by (select count(*) from film_actor fa where fa.actor_id = a.actor_id) desc
limit 1
Note that neither your query nor this one take in account the possibility of top ties. Your question does not specify that. If that's what needed here, then the strategy would be different - but it seems this is not what you asked for.