在子查询用inner join连接film表和film_category表并选出film_id,这时子查询中选出的就是全部有分类的电影id,然后在主查询中从film表选出film_id和title并限制film_id不在子查询结果中。
select film_id, title from film
where film_id not in
(select f.film_id
from film as f
inner join film_category as fc
on f.film_id = fc.film_id)
用left join连接film表和film_category表,这时如果没有分类,category_id字段为NULL。因此我们从中选出film_id和title并限制category_id字段is NULL。
select f.film_id, f.title
from film as f
left join film_category as fc
on f.film_id = fc.film_id
where fc.category_id is NULL