user1971469
user1971469

Reputation: 23

Ms Access | Issues with INNER JOIN query

So, I'm doing a movie database and I got one table for actors and one table for movie titles.

In the Movies table I got Three columns for Actors. Actor_1, Actor_2, Actor_3. In these fields, I only write numbers which corresponds to a row in the Actors table.

Each actor have these columns:

Actor_ID, Firstname, Surname 

Now if I do this query:

SELECT movie.titel, firstname + ' ' + surname AS name

FROM Movie

INNER JOIN Actors ON movie.actor_1=actor.actor_id

Then I get almost what I want. I get the movie titles but only one actor per movie. I don't know how I am supposed to do for the movies where I got two or three actors.

I had to translate to code so it would be more understandable. The code in its original shape works so don't mind if it's not 100% here. Just would appreciate some pointers on how I could do.

Upvotes: 2

Views: 474

Answers (1)

Fionnuala
Fionnuala

Reputation: 91356

You need to change your table design to include a junction table. So you will have

Movies
ID
Etc

Actors
ID
Etc

MoviesActors
MovieID
ActorID
Etc

Your query might be:

SELECT m.MovieTitle, a.ActorName
FROM Actors a 
INNER JOIN (Movies 
INNER JOIN MoviesActors ma
ON m.ID = ma.MovieID) 
ON a.ID = ma.ActorID

Relational database design
Junction tables

Upvotes: 4

Related Questions