Appendix D. Structured Query Language (SQL)
For our purposes, a database is a collection of tables containing data that you can query data from. A table is a collection of data with a known structure, and a query is a statement about what you want from the table.
For example, consider a database of students in a school, where each table is a class (Tables D-1 and D-2).
student_id | first_name | last_name | major | grade |
---|---|---|---|---|
58394 |
Doy |
Easterbrook |
computer science |
80 |
29485 |
Merridie |
Blockwell |
history |
85 |
92554 |
Denys |
Phorsby |
physics |
95 |
02359 |
Coreen |
Otley |
english |
90 |
02945 |
Merci |
Wiszniewski |
history |
95 |
student_id | first_name | last_name | major | grade |
---|---|---|---|---|
09528 |
Teodoro |
Anscombe |
english |
85 |
10394 |
Kala |
Tidcombe |
english |
85 |
85422 |
Theodosia |
Kelson |
computer science |
90 |
25925 |
Saunderson |
Dunlap |
english |
90 |
29485 |
Merridie |
Blockwell |
history |
95 |
92554 |
Denys |
Phorsby |
physics |
95 |
02359 |
Coreen |
Otley |
english |
85 |
02945 |
Merci |
Wiszniewski |
history |
95 |
To see the student_id
for every student in History 101, you would use the following query:
SELECT student_id FROM History101;
and would receive this output:
+------------+ | student_id | +------------+ | 09528 | | 10394 | | 85422 | | 25925 | | 29485 | | 92554 | | 02359 | | 02945 | +------------+
This type of SELECT
statement works on any combination of the columns:
SELECT student_id, major FROM History101;
+------------+------------------+ | student_id | major | +------------+------------------+ ...
Get Hands-On Differential Privacy now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.