-
Notifications
You must be signed in to change notification settings - Fork 0
/
Challenge: Sequels in SQL
27 lines (24 loc) · 1003 Bytes
/
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
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 AS "movie_title", sequel.title AS "sequel_title"
FROM movies
LEFT OUTER JOIN movies sequel
ON sequel.id = movies.sequel_id;