I\'m having a ton of trouble thinking in terms of SQL on problems like this. I don\'t know how I should be structuring my queries. Should I be joining film
on
You should use inner join
SELECT
film.title
, language.name
FROM film
INNER JOIN language on film.language_id = language.language_id
INNER JOIN film_actor on film.film_id = film_actor.film_id
INNER JOIN actor on actor.actor_id = film_actor.actor_id
WHERE actor.first_name = 'ADAM'
AND actor.last_name ='GRANT'
You could use NATURAL JOIN
, which removes the range variables (film_actor
, actor
) from the query, as well as the 'stating the blooming obvious' search conditions (actor_id = actor_id):
SELECT title AS film_title, name AS language_name
FROM film
NATURAL JOIN film_actor
NATURAL JOIN actor
NATURAL JOIN language
WHERE first_name = 'ADAM'
AND last_name ='GRANT';
I'm not a great fan of the school of thought where a data element such as "name of language" is just called just name
and the context language
is supposed to come from the table name. What works well in Java classes doesn't necessarily translate to SQL, which is why I find I need to use a rename in the query (SELECT name AS language_name...
). Additionally, you have a name
attribute in category
, and you would have problems if you ever had NATURAL JOIN
s including both language
and category
. Much better to have unique and consistent attribute names throughout your schema, as you have successfully done with actor_id
, for example.