题解 | #使用join查询方式找出没有分类的电影id以及名称#
使用join查询方式找出没有分类的电影id以及名称
http://www.nowcoder.com/practice/a158fa6e79274ac497832697b4b83658
解题思路分析:
分析:电影没有被分类有两层意思 >> 给定的film表中的电影id没有在film_category中出现
SQL思路:
方法1. 利用左连接求出film表与film_category表的连接情况,得出一张临时表。若电影没有被分类,那么得出的临时表中对应film的film_category为null.(左连接 + is null) select f.film_id as '电影id', f.title as '名称' from film as f left join film_category as fc on f.film_id = fc.film_id where fc.category_id is null 方法2:首先求出film表与film_category表中已经被分类的电影情况,即得出一张临时分类电影表;然后结合film表,利用not in找出不在分类电影表的电影.(内连接 + not in) select film_id as '电影id', title as '名称' 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)