此类问题很明显采用外连接+where IS NULL过滤,或者内连接 NOT IN 取补集
方案1:外连接+where
SELECT f.film_id AS '电影id',f.title AS '名称' FROM film f LEFT JOIN film_category fc ON f.film_id = fc.film_id WHERE fc.category_id IS NULL
方案2:找出有分类的电影film_id的集合,NOT IN 反转得未分类电影作为where子查询
SELECT film_id AS '电影id',title AS '名称' FROM film WHERE film_id NOT IN (SELECT f.film_id FROM film f INNER JOIN film_category fc ON f.film_id = fc.film_id);