Queries and the Power of Join


Totally superficial intro to SQL

SQL: Structured Query Language

The JOIN command


Simple Examples

SELECT * FROM Term;

Term TermName Year StartDate
F16 Fall 2016 09/12/2016
W17 Winter 2017 01/03/2017
S17 Spring 2017 03/27/2017
F17 Fall 2017 09/11/2017

SELECT TermName, Year, StartDate FROM Term ORDER BY StartDate;

TermName Year StartDate
Fall 2016 09/12/2016
Winter 2017 01/03/2017
Spring 2017 03/27/2017
Fall 2017 09/11/2017

SELECT PKey, CourseCode, Section, Term
FROM Offerings WHERE CourseCode = 'COMP 105' ORDER BY PKey;

PKey CourseCode Section Term
1 COMP 105 01 F16
2 COMP 105 02 F16
7 COMP 105 01 W17
19 COMP 105 01 F17
20 COMP 105 02 F17

SELECT CourseCode, Section, TermName, Year, StartDate
FROM Offerings LEFT JOIN Term ON Offerings.Term = Term.Term
WHERE CourseCode = 'COMP 105' ORDER BY StartDate, CourseCode, Section;

CourseCode Section TermName Year StartDate
COMP 105 01 Fall 2016 09/12/2016
COMP 105 02 Fall 2016 09/12/2016
COMP 105 01 Winter 2017 01/03/2017
COMP 105 01 Fall 2017 09/11/2017
COMP 105 02 Fall 2017 09/11/2017

Alyce Brady, Kalamazoo College