Two Table Equi-Joins(join on)
SQL>
SQL>
SQL> CREATE TABLE Class (
2 ClassID INT NOT NULL PRIMARY KEY,
3 CourseID INT NOT NULL,
4 InstructorID INT NOT NULL,
5 RoomID INT NOT NULL,
6 Time VARCHAR(50));
Table created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (1,1,1,6,'Mon 09:00-11:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (2,2,1,5,'Mon 11:00-12:00, Thu 09:00-11:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (3,3,2,3,'Mon 14:00-16:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (4,4,3,2,'Tue 10:00-12:00, Thu 14:00-15:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (5,5,2,9,'Tue 14:00-16:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (6,6,3,2,'Tue 16:00-17:00, Thu 15:00-17:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (7,7,4,3,'Wed 09:00-11:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (8,8,5,8,'Wed 11:00-13:00, Fri 09:00-11:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (9,9,1,5,'Fri 11:00-13:00');
1 row created.
SQL> INSERT INTO Class (ClassID,CourseID,InstructorID,RoomID,Time) VALUES (10,10,6,9,'Fri 14:00-16:00');
1 row created.
SQL>
SQL> CREATE TABLE Room (
2 RoomID INT NOT NULL PRIMARY KEY,
3 Comments VARCHAR(50),
4 Capacity INT);
SQL>
SQL>
SQL> SELECT Class.ClassID, Class.Time, Room.RoomID
2 FROM Room
3 JOIN Class ON Room.RoomID = Class.RoomID;
CLASSID TIME ROOMID
---------- -------------------------------------------------- ----------
1 Mon 09:00-11:00 6
2 Mon 11:00-12:00, Thu 09:00-11:00 5
3 Mon 14:00-16:00 3
4 Tue 10:00-12:00, Thu 14:00-15:00 2
5 Tue 14:00-16:00 9
6 Tue 16:00-17:00, Thu 15:00-17:00 2
7 Wed 09:00-11:00 3
8 Wed 11:00-13:00, Fri 09:00-11:00 8
9 Fri 11:00-13:00 5
10 Fri 14:00-16:00 9
10 rows selected.
SQL>
SQL> drop table class;
Table dropped.
SQL> drop table room;
Table dropped.
Related examples in the same category