10.7k views
3 votes
What is the SQL query to select the name of a person from the Person table who is also an actor in a movie?

User JoakimB
by
7.8k points

1 Answer

2 votes

Final answer:

To retrieve the name of a person who is an actor in a movie from a database, use a SQL query to join the Person table with the Movies through a Cast table.

Step-by-step explanation:

To select the name of a person from the Person table who is also an actor in a movie, we need to assume there is a linkage between the Person table and the movies they have acted in, typically through a Movies table or a junction table if many-to-many relationships are present. Here's a sample SQL query:

SELECT Person.name FROM Person INNER JOIN Cast ON Person.id = Cast.person_id INNER JOIN Movie ON Cast.movie_id = Movie.id WHERE Cast.role = 'Actor';

This query selects the name field from the Person table and joins it with a Cast table on a common person_id, then joins with the Movie table on a common movie_id. The WHERE clause specifically looks for the role of an 'Actor' to ensure we are retrieving only persons who have acted in a movie.

User Sunil Targe
by
7.7k points