-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path041.sql
More file actions
44 lines (37 loc) · 1.09 KB
/
041.sql
File metadata and controls
44 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Q: Show patient_id, first_name, last_name from patients whose does not have any records in the admissions table. (Their patient_id does not exist in any admissions.patient_id rows.)
Table Info: patients
+--------------+----------+
| Column Name | Type |
+--------------+----------+
| patient_id | INT |
| first_name | TEXT |
| last_name | TEXT |
| gender | CHAR(1) |
| birth_date | DATE |
| city | TEXT |
| province_id | CHAR(2) |
| allergies | TEXT |
| height | INT |
| weight | INT |
+--------------+----------+
Table Info: admissions
+----------------------+----------+
| Column Name | Type |
+----------------------+----------+
| patient_id | INT |
| admission_date | DATE |
| discharge_date | DATE |
| diagnosis | TEXT |
| attending_doctor_id | INT |
+----------------------+----------+
*/
-- SOLUTION:
select
p.patient_id,
p.first_name,
p.last_name
from patients p
where p.patient_id not in (
select a.patient_id
from admissions a
);