I created a database that contains info about movies and actors etc. Among others, I've created these tables:
CREATE TABLE Movie
(
Movie_ID PRIMARY KEY NOT NULL idenity(1,1),
Movie_title varchar(50),
....
)
CREATE TABLE Actor
(
Actor_ID PRIMARY KEY NOT NULL identity(1,1),
Actor_Name varchar(50),
Actor_Surname varchar(50),
.....
)
and I link them using the following table:
CREATE TABLE Has_Actor
(
Has_Actor_ID PRIMARY KEY NOT NULL identity(1,1),
Has_Actor_M_ID foreign key references Movie(Movie_ID),
Has_Actor_A_ID foreign key references Actor(Actor_ID),
)
Now I want to view the actor's who played in the most movies, name and surname, so I tried the following select statement:
SELECT
Actor.Actor_Name, Actor.Actor_Surname
FROM
Actor, Has_Actor
WHERE
Has_Actor_A_ID = Actor.Actor_ID
AND Actor.Actor_ID = (SELECT MAX(distinct COUNT(Has_Actor.Actor_ID)))
And when I execute this I get this error:
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
I know that there is a mistake at the point where i use the max and count functions but I can't understand what is wrong. can you please help me?