Skip to content

Commit b6e5e39

Browse files
refactor 1350
1 parent d6f75be commit b6e5e39

File tree

1 file changed

+0
-71
lines changed

1 file changed

+0
-71
lines changed

Diff for: database/_1350.sql

-71
Original file line numberDiff line numberDiff line change
@@ -1,72 +1 @@
1-
--1350. Students With Invalid Departments
2-
--
3-
--Table: Departments
4-
--
5-
--+---------------+---------+
6-
--| Column Name | Type |
7-
--+---------------+---------+
8-
--| id | int |
9-
--| name | varchar |
10-
--+---------------+---------+
11-
--id is the primary key of this table.
12-
--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
721
select id, name from Students where department_id not in (select id from Departments);

0 commit comments

Comments
 (0)