-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueries
More file actions
52 lines (48 loc) · 966 Bytes
/
Queries
File metadata and controls
52 lines (48 loc) · 966 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
1. Get all books from newest to oldest
===============================
SELECT
title,
publication_date
FROM
books
ORDER BY
publication_date
DESC;
===============================
2. Get the oldest book from every author
===============================
SELECT
title,
first_name,
last_name,
publication_date
FROM
books
LEFT JOIN authors ON books.fk_author = authors.id
ORDER BY
publication_date ASC
LIMIT 3;
===============================
3. Get all books that have a book series
===============================
SELECT
title,
series
FROM
books
LEFT JOIN series ON books.fk_series = series.id
WHERE
series IS NOT NULL;
===============================
4. Get every author's book count
===============================
SELECT
first_name,
last_name,
COUNT(books.id) AS Book_Count
FROM
books
LEFT JOIN authors ON books.fk_author = authors.id
GROUP BY
fk_author;
===============================