-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql5.2.sql
More file actions
67 lines (52 loc) · 1.5 KB
/
sql5.2.sql
File metadata and controls
67 lines (52 loc) · 1.5 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
66
67
USE moviesdb;
SELECT m.movie_id, title, budget, revenue, currency, unit
FROM movies m
JOIN financials f
ON m.movie_id = f.movie_id;
# By default inner join
SELECT m.movie_id, title, budget, revenue, currency, unit
FROM movies m
LEFT JOIN financials f
ON m.movie_id = f.movie_id;
SELECT m.movie_id, title, budget, revenue, currency, unit
FROM movies m
RIGHT JOIN financials f
ON m.movie_id = f.movie_id;
SELECT f.movie_id, title, budget, revenue, currency, unit
FROM movies m
RIGHT JOIN financials f
ON m.movie_id = f.movie_id;
SELECT m.movie_id, title, budget, revenue, currency, unit
FROM movies m
LEFT JOIN financials f
ON m.movie_id = f.movie_id
UNION
SELECT f.movie_id, title, budget, revenue, currency, unit
FROM movies m
RIGHT JOIN financials f
ON m.movie_id = f.movie_id;
SELECT movie_id, title, budget, revenue, currency, unit
FROM movies m
LEFT JOIN financials f
USING (movie_id);
SELECT movie_id, title, budget, revenue, currency, unit
FROM movies m
RIGHT JOIN financials f
USING (movie_id);
-- 1. Show all the movies with their language names
SELECT m.title, l.name
FROM movies m
JOIN languages l
USING (language_id);
-- 2. Show all Telugu movie names (assuming you don't know the language id for Telugu)
SELECT m.title, l.name
FROM movies m
JOIN languages l
USING (language_id)
WHERE l.name = "Telugu";
-- 3. Show the language and number of movies released in that language--
SELECT l.name, COUNT(m.movie_id) as no_movies
FROM languages l
LEFT JOIN movies m
USING (language_id)
GROUP BY language_id;