-
Notifications
You must be signed in to change notification settings - Fork 757
Expand file tree
/
Copy path5.sql
More file actions
29 lines (25 loc) · 858 Bytes
/
5.sql
File metadata and controls
29 lines (25 loc) · 858 Bytes
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
# Solution 1
/* Assumes band names are unique */
SELECT DISTINCT(bands.name) AS 'Band Name'
FROM bands
LEFT JOIN albums ON bands.id = albums.band_id
WHERE albums.band_id IS NULL;
/* No such assumption */
# Solution 2
SELECT bands.name AS 'Band Name'
FROM bands
INNER JOIN (
SELECT bands.id as id
FROM bands
LEFT JOIN albums ON bands.id = albums.band_id
WHERE albums.band_id IS NULL
) AS bands_with_no_albums
ON bands.id = bands_with_no_albums.id;
/*
Note:
There's an issue with the given solution: https://github.com/WebDevSimplified/Learn-SQL/issues/8
The fellow who closed it must have changed the mode of SQL to something else.
But it's been suggested to use full_group_by mode for SQL to avoid "inconsistencies".
(Basically, find a different way to solve your problem
without using columns in SELECT that were not included in your GROUP BY.)
*/