-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.sql
More file actions
36 lines (28 loc) · 1.37 KB
/
db.sql
File metadata and controls
36 lines (28 loc) · 1.37 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
CREATE TABLE flights (
id SERIAL PRIMARY KEY,
origin VARCHAR NOT NULL,
destination VARCHAR NOT NULL,
duration INTEGER NOT NULL
);
/* CREATION OF flights TABLE */
INSERT INTO flights (origin, destination, duration) VALUES ('New York', 'London', 415);
INSERT INTO flights (origin, destination, duration) VALUES ('New Jersey', 'Dubai', 315);
INSERT INTO flights (origin, destination, duration) VALUES ('Tokyo', 'Los Angeles', 425);
INSERT INTO flights (origin, destination, duration) VALUES ('Hong Kong', 'Paris', 275);
INSERT INTO flights (origin, destination, duration) VALUES ('New york', 'Istanbul', 245);
/* INSERTION OF flights TABLE */
CREATE TABLE passengers (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
flight_id INTEGER REFERENCES flights
);
/* CREATION OF passengers TABLE an create REFERENCES btw id and flight_id*/
INSERT INTO passengers ( name, flight_id) VALUES ('Nancy', 4);
INSERT INTO passengers ( name, flight_id) VALUES ('June', 1);
INSERT INTO passengers ( name, flight_id) VALUES ('May', 2);
INSERT INTO passengers ( name, flight_id) VALUES ('Ash', 3);
INSERT INTO passengers ( name, flight_id) VALUES ('Ray', 5);
INSERT INTO passengers ( name, flight_id) VALUES ('Sammy', 1);
/* INSERTION OF passengers TABLE */
SELECT origin,destination,duration,name FROM flights JOIN passengers ON passengers.flight_id = flights.id;
/* JOINin two tables et al */