-
Notifications
You must be signed in to change notification settings - Fork 0
/
challange12_Sequels_in_SQL.sql
30 lines (26 loc) · 1.11 KB
/
challange12_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
23
24
25
26
27
28
29
30
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);
/*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).*/
SELECT movies.title AS "movie_title", sequel.title AS "sequel_title"
FROM movies
LEFT OUTER JOIN movies sequel
ON movies.sequel_id = sequel.id;