Reputation: 134
I am trying to Write a query that produces the title of every action film with a rating of PG-13, R, or NC-17.
Here is my SQL:
SELECT title
FROM film
INNER JOIN film_category ON film.film_id = film_category.film_id
INNER JOIN category ON film_category.category_id = category.category_id
WHERE category.name = "Action"
WHERE film.rating = "PG-13" OR "R" OR "NC-17";
I believe the problem is in my syntax in my film.rating conditioning. I am new to SQL. I would appreciate if someone could show me in the right direction!
Upvotes: 2
Views: 6112
Reputation: 1269623
You have several errors in your SQL. I would write this as:
SELECT f.title
FROM film f INNER JOIN
film_category fc
ON f.film_id = fc.film_id INNER JOIN
category c
ON fc.category_id = c.category_id
WHERE c.name = 'Action' AND f.rating IN ('PG-13', 'R', 'NC-17');
Notes:
WHERE
is used at most one time per SELECT
.OR
is for boolean expressions, not constants. You want IN
.Upvotes: 2
Reputation: 43574
Try the following:
SELECT title
FROM film f INNER JOIN film_category fc ON f.film_id = fc.film_id
INNER JOIN category c ON fc.category_id = c.category_id
WHERE c.name = 'Action'
AND f.rating IN ('PG-13', 'R', 'NC-17');
Upvotes: 2