-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoin.sql
More file actions
74 lines (52 loc) · 1.12 KB
/
Join.sql
File metadata and controls
74 lines (52 loc) · 1.12 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use books;
# List the title id, title name, and primary author of all books
select
distinct titles.title_id,
titles.title_name,
authors.au_lname
from
titles
inner join title_authors on
titles.title_id = title_authors.title_id
inner join authors on
title_authors.au_id = authors.au_id;
# List the title id, title name, publisher id, ad publisher name of all books
select
titles.title_id,
titles.title_name,
publishers.pub_id,
publishers.pub_name
from
titles
inner join publishers on
titles.pub_id = publishers.pub_id
order by
titles.title_id;
# Same as above except books published only in CA
select
titles.title_id,
titles.title_name,
publishers.pub_id,
publishers.pub_name
from
titles
inner join publishers on
titles.pub_id = publishers.pub_id
where
publishers.state = 'CA'
order by
titles.title_id;
# List type and number of books published in CA
select
titles.type,
title_authors.au_order as 'Number'
from
titles
inner join title_authors on
titles.title_id = title_authors.title_id
inner join publishers on
titles.pub_id = publishers.pub_id
where
publishers.state = 'CA'
group by
titles.type;