You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--The table has information about the id of each department of a university.
13
-
--
14
-
--
15
-
--Table: Students
16
-
--
17
-
--+---------------+---------+
18
-
--| Column Name | Type |
19
-
--+---------------+---------+
20
-
--| id | int |
21
-
--| name | varchar |
22
-
--| department_id | int |
23
-
--+---------------+---------+
24
-
--id is the primary key of this table.
25
-
--The table has information about the id of each student at a university and the id of the department he/she studies at.
26
-
--
27
-
--
28
-
--Write an SQL query to find the id and the name of all students who are enrolled in departments that no longer exists.
29
-
--
30
-
--Return the result table in any order.
31
-
--
32
-
--The query result format is in the following example:
33
-
--
34
-
--Departments table:
35
-
--+------+--------------------------+
36
-
--| id | name |
37
-
--+------+--------------------------+
38
-
--| 1 | Electrical Engineering |
39
-
--| 7 | Computer Engineering |
40
-
--| 13 | Bussiness Administration |
41
-
--+------+--------------------------+
42
-
--
43
-
--Students table:
44
-
--+------+----------+---------------+
45
-
--| id | name | department_id |
46
-
--+------+----------+---------------+
47
-
--| 23 | Alice | 1 |
48
-
--| 1 | Bob | 7 |
49
-
--| 5 | Jennifer | 13 |
50
-
--| 2 | John | 14 |
51
-
--| 4 | Jasmine | 77 |
52
-
--| 3 | Steve | 74 |
53
-
--| 6 | Luis | 1 |
54
-
--| 8 | Jonathan | 7 |
55
-
--| 7 | Daiana | 33 |
56
-
--| 11 | Madelynn | 1 |
57
-
--+------+----------+---------------+
58
-
--
59
-
--Result table:
60
-
--+------+----------+
61
-
--| id | name |
62
-
--+------+----------+
63
-
--| 2 | John |
64
-
--| 7 | Daiana |
65
-
--| 4 | Jasmine |
66
-
--| 3 | Steve |
67
-
--+------+----------+
68
-
--
69
-
--John, Daiana, Steve and Jasmine are enrolled in departments 14, 33, 74 and 77 respectively. department 14, 33, 74 and 77 doesn't exist in the Departments table.
70
-
71
-
--# Write your MySQL query statement below
72
1
select id, name from Students where department_id not in (select id from Departments);
0 commit comments