题目
Table: Departments
1 | +---------------+---------+ |
Table: Students
1 | +---------------+---------+ |
Write an SQL query to find the id and the name of all students who are enrolled in departments that no longer exists.
Return the result table in any order.
Example 1:
1 | Departments table: |
解法
解法一:
题目大意就是找过所有没有注册过公寓的学生。即该学生的公寓不在给定的公寓中。
用子查询
SQL
1 | select id, name from Students where department_id not in (select id from Departments) |