-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChallenge: Sequels In SQL
38 lines (30 loc) · 1.24 KB
/
Challenge: Sequels In SQL
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
/*
Challenge: Sequels in SQL
Step 1 -
We've created a table with all the 'Harry Potter' movies, with a sequel_id column that matches the id of the sequel for each movie.
Issue a SELECT that will show the title of each movie next to its sequel's title (or NULL if it doesn't have a sequel).
*/
CREATE TABLE movies (id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
released INTEGER,
sequel_id INTEGER);
INSERT INTO movies
VALUES (1, "Harry Potter and the Philosopher's Stone", 2001, 2);
INSERT INTO movies
VALUES (2, "Harry Potter and the Chamber of Secrets", 2002, 3);
INSERT INTO movies
VALUES (3, "Harry Potter and the Prisoner of Azkaban", 2004, 4);
INSERT INTO movies
VALUES (4, "Harry Potter and the Goblet of Fire", 2005, 5);
INSERT INTO movies
VALUES (5, "Harry Potter and the Order of the Phoenix ", 2007, 6);
INSERT INTO movies
VALUES (6, "Harry Potter and the Half-Blood Prince", 2009, 7);
INSERT INTO movies
VALUES (7, "Harry Potter and the Deathly Hallows – Part 1", 2010, 8);
INSERT INTO movies
VALUES (8, "Harry Potter and the Deathly Hallows – Part 2", 2011, NULL);
SELECT movies.title, sequel.title
AS sequel from movies
LEFT OUTER JOIN movies sequel
ON movies.sequel_id = sequel.id ;