MS Access – Finding Movie Names and Year with at Least 5 Actors

ms access

Given database of the website "eMovies" that manage data about cinema movies.

Write in SQL query that finds the names and the year of the movies that have at least 5 actors.

enter image description here

My attempt:

The idea: to do a natural joint between "Movies" and "ActorsMovies" tables, and then to count the rows with the same MovieID, and then to check if count>5

I succeded to count the rows thank's to @Phil's advice, but still I need the name of the movies and the year,

Here is my start:

SELECT DISTINCT Year, MovieName
FROM Movies, ActrorsMovies
SELECT Count(ActorsMovies.MovieID) 
FROM ActorsMovies
GROUP BY ActorsMovies.MovieID
HAVING (((Count(ActorsMovies.ActorID))>5)); 

This code does not work


EDIT: another attempt

 SELECT DISTINCT Movies.Year, Movies.MovieName
 FROM Movies, ActorsMovies
 GROUP BY ActorsMovies.MovieID
 HAVING Count(ActorsMovies.ActorID)>5;

Best Answer

You were close

SELECT M.MovieID, M.MovieName, M.Year 
  FROM Movies M
 INNER JOIN ActorsMovies AM 
         ON AM.MovieID = M.MovieID
 GROUP BY M.MovieID, M.MovieName, M.Year
HAVING COUNT(AM.ActorID) > 5

You could probably just use count(*) > 5