-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sequels_in_SQL.sql
22 lines (21 loc) · 934 Bytes
/
Sequels_in_SQL.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 h.title, s.title from movies as h left outer join movies as s on h.sequel_id=s.id;