-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04LeftJoin.sql
More file actions
38 lines (32 loc) · 752 Bytes
/
04LeftJoin.sql
File metadata and controls
38 lines (32 loc) · 752 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
SELECT b.title, a.name
FROM authors AS a, books AS b
WHERE a.author_id = b.author_id
limit 10
;
SELECT b.title, a.name
FROM authors AS a
INNER JOIN books AS b
ON a.author_id = b.author_id
LIMIT 10
;
____
SELECT a.author_id, a.name, a.nationality, b.title
FROM authors as a
JOIN books as b
ON b.author_id = a.author_id
WHERE a.author_id between 1 and 5
SELECT a.author_id, a.name, a.nationality, b.title
FROM authors as a
LEFT JOIN books as b
ON b.author_id = a.author_id
WHERE a.author_id between 1 and 5
ORDER BY a.author_id
;
SELECT a.author_id, a.name, a.nationality, COUNT(b.book_id)
FROM authors as a
LEFT JOIN books as b
ON b.author_id = a.author_id
WHERE a.author_id between 1 and 5
GROUP BY a.author_id
ORDER BY a.author_id
;