-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtutor.py
More file actions
1419 lines (1262 loc) · 61.8 KB
/
tutor.py
File metadata and controls
1419 lines (1262 loc) · 61.8 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
SQLite3 Library — Interactive Terminal Tutor
Walks adult students through SQL fundamentals using sqlite3.
Usage: python3 tutor.py
"""
import os
import sys
import json
import sqlite3
import textwrap
import readline # noqa: F401 — enables arrow-key history in input()
# ── ANSI color helpers ───────────────────────────────────────────────────────
RESET = "\033[0m"
BOLD = "\033[1m"
DIM = "\033[2m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
CYAN = "\033[36m"
RED = "\033[31m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
WHITE = "\033[97m"
def c(text, *codes):
return "".join(codes) + str(text) + RESET
def hr(char="─", width=70, colour=DIM):
return c(char * width, colour)
def banner(text):
line = "═" * 70
print(c(line, BOLD + CYAN))
print(c(f" {text}", BOLD + CYAN))
print(c(line, BOLD + CYAN))
def section(text):
print(c(f"\n {text}", BOLD + YELLOW))
print(c(" " + "─" * (len(text) + 2), DIM))
def info(text):
for line in text.splitlines():
print(c(f" {line}", WHITE))
def hint_text(text):
print(c(f" 💡 {text}", CYAN))
def success(text):
print(c(f"\n ✔ {text}", GREEN + BOLD))
def error(text):
print(c(f"\n ✖ {text}", RED + BOLD))
def prompt_line():
print()
return input(c(" sqlite> ", BOLD + GREEN)).strip()
# ── Progress tracking ────────────────────────────────────────────────────────
PROGRESS_FILE = os.path.join(os.path.dirname(__file__), ".progress.json")
def load_progress():
if os.path.exists(PROGRESS_FILE):
try:
with open(PROGRESS_FILE) as f:
return json.load(f)
except Exception:
pass
return {"completed": []}
def save_progress(progress):
with open(PROGRESS_FILE, "w") as f:
json.dump(progress, f, indent=2)
def mark_done(exercise_id, progress):
if exercise_id not in progress["completed"]:
progress["completed"].append(exercise_id)
save_progress(progress)
# ── Database helpers ─────────────────────────────────────────────────────────
DB_PATH = os.path.join(os.path.dirname(__file__), "library.db")
def get_connection():
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA foreign_keys = ON")
return conn
def run_sql(conn, sql, quiet=False):
"""Execute one or more SQL statements; pretty-print results."""
statements = [s.strip() for s in sql.split(";") if s.strip()]
any_rows = False
for stmt in statements:
try:
cur = conn.execute(stmt)
conn.commit()
rows = cur.fetchall()
if rows:
any_rows = True
_print_table(cur.description, rows)
elif cur.rowcount > 0 and not quiet:
success(f"{cur.rowcount} row(s) affected.")
elif not quiet and not any_rows and not rows:
print(c(" (no rows returned)", DIM))
except sqlite3.Error as e:
error(str(e))
return False
return True
def _print_table(description, rows):
if not description:
return
col_names = [d[0] for d in description]
col_widths = [len(n) for n in col_names]
str_rows = []
for row in rows:
str_row = [str(v) if v is not None else "NULL" for v in row]
str_rows.append(str_row)
for i, val in enumerate(str_row):
col_widths[i] = max(col_widths[i], len(val))
sep = " +" + "+".join("-" * (w + 2) for w in col_widths) + "+"
header = " |" + "|".join(
c(f" {col_names[i]:<{col_widths[i]}} ", BOLD + CYAN)
for i in range(len(col_names))
) + "|"
print(sep)
print(header)
print(sep)
for str_row in str_rows:
row_str = " |" + "|".join(
f" {str_row[i]:<{col_widths[i]}} " for i in range(len(str_row))
) + "|"
print(row_str)
print(sep)
print(c(f" {len(rows)} row(s).", DIM))
def handle_dot_command(conn, cmd):
"""Emulate common sqlite3 CLI dot-commands."""
parts = cmd.strip().split()
name = parts[0].lower()
if name == ".quit" or name == ".exit":
print(c("\n Goodbye! Keep practicing.\n", BOLD + CYAN))
sys.exit(0)
elif name == ".help":
print(c("""
Dot-commands available in this tutor:
.tables List all tables
.schema [table] Show CREATE statement(s)
.databases Show attached databases
.mode column (acknowledged — output is always column mode)
.headers on/off (acknowledged — headers are always shown)
.nullvalue <str> Set string for NULL display
.read <file> Execute SQL from a file
.quit / .exit Exit the tutor
.help Show this message
""", CYAN))
elif name == ".tables":
cur = conn.execute(
"SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"
)
rows = cur.fetchall()
if rows:
print(" " + " ".join(r[0] for r in rows))
else:
print(c(" (no tables yet)", DIM))
elif name == ".schema":
table = parts[1] if len(parts) > 1 else None
if table:
cur = conn.execute(
"SELECT sql FROM sqlite_master WHERE type='table' AND name=?;",
(table,),
)
else:
cur = conn.execute(
"SELECT sql FROM sqlite_master WHERE type='table' ORDER BY name;"
)
rows = cur.fetchall()
if rows:
for row in rows:
if row[0]:
print(c(" " + row[0], CYAN))
else:
print(c(" (nothing found)", DIM))
elif name == ".databases":
cur = conn.execute("PRAGMA database_list;")
rows = cur.fetchall()
_print_table(cur.description, rows)
elif name in (".mode", ".headers", ".separator", ".nullvalue"):
print(c(f" ('{name}' acknowledged — formatting is handled by the tutor)", DIM))
elif name == ".read":
if len(parts) < 2:
error("Usage: .read <filename>")
return
filepath = parts[1]
if not os.path.isabs(filepath):
filepath = os.path.join(os.path.dirname(__file__), filepath)
if not os.path.exists(filepath):
error(f"File not found: {filepath}")
return
with open(filepath) as fh:
sql = fh.read()
print(c(f" Reading {filepath} …", DIM))
run_sql(conn, sql)
else:
print(c(f" Unknown dot-command: {cmd} (try .help)", YELLOW))
# ── Exercise definitions ─────────────────────────────────────────────────────
EXERCISES = [
{
"id": 1,
"title": "What is a Database?",
"concept": "Relational model, tables, rows, columns",
"intro": """\
Welcome to Exercise 1!
A *relational database* stores data in tables — grids of rows and columns,
a bit like a spreadsheet. Unlike a spreadsheet, the database enforces rules,
handles millions of rows efficiently, and lets multiple programs share the
same data safely.
A *row* (also called a record) is one entry.
A *column* (also called a field) is one attribute of that entry.
A *table* is the collection of all rows with the same columns.
In this tutor you will work with a small public-library database: library.db.
Let's explore the sqlite3 dot-commands first. These are not SQL — they are
special commands understood by the sqlite3 shell (and this tutor).""",
"tasks": [
"Type .databases to see the attached database file.",
"Type .tables to list all tables (none yet — that's OK).",
"Type .help to browse available dot-commands.",
"Type .done when you have tried all three.",
],
"hints": [
"Dot-commands start with a dot (.) and are not followed by a semicolon.",
"Try each command one at a time and read the output carefully.",
],
"reflection": [
"What is a 'relation' in the relational model?",
"Why use a database instead of a plain spreadsheet?",
"What is the difference between a row and a record?",
],
"setup": [],
},
{
"id": 2,
"title": "Creating Tables",
"concept": "CREATE TABLE, data types (INTEGER, TEXT)",
"intro": """\
Exercise 2 — Creating Tables
Before you can store data you need to define its *schema* — the structure of
your tables, their column names, and the data type of each column.
SQLite3 supports these core types:
INTEGER — whole numbers
REAL — floating-point numbers
TEXT — character strings
BLOB — raw binary data
NULL — the absence of a value
Every table should have a *primary key* — a column (or set of columns) that
uniquely identifies each row. Using INTEGER PRIMARY KEY AUTOINCREMENT lets
SQLite assign IDs automatically.""",
"tasks": [
"Create the 'authors' table (copy the SQL below and press Enter).",
"Create the 'books' table.",
"Use .tables to confirm both tables exist.",
"Use .schema authors and .schema books to inspect them.",
],
"example_sql": """\
CREATE TABLE authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);
CREATE TABLE books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"hints": [
"End every SQL statement with a semicolon (;).",
"NOT NULL means the column must always have a value.",
"AUTOINCREMENT means SQLite will fill in the id automatically.",
"If you get 'table already exists', that's fine — it was set up for you.",
],
"reflection": [
"Why is 'id' an INTEGER instead of TEXT?",
"What happens if you omit NOT NULL on a column?",
"What other data types might a library database need?",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
],
},
{
"id": 3,
"title": "Inserting Data",
"concept": "INSERT INTO … VALUES",
"intro": """\
Exercise 3 — Inserting Data
Now that the tables exist, let's populate them. The INSERT INTO statement
adds a new row to a table.
Syntax:
INSERT INTO table_name (col1, col2, …) VALUES (val1, val2, …);
You can omit a column if it has a default value or allows NULL.
The 'id' column is AUTOINCREMENT so we never provide it ourselves.""",
"tasks": [
"Insert at least 6 authors using the examples below.",
"Insert at least 6 books.",
"Try omitting a NOT NULL column (title) to see the error.",
"Run SELECT * FROM authors; to verify your inserts.",
],
"example_sql": """\
INSERT INTO authors (name, birth_year) VALUES ('Toni Morrison', 1931);
INSERT INTO authors (name, birth_year) VALUES ('George Orwell', 1903);
INSERT INTO authors (name, birth_year) VALUES ('James Baldwin', 1924);
INSERT INTO authors (name, birth_year) VALUES ('Octavia Butler', 1947);
INSERT INTO authors (name, birth_year) VALUES ('Ursula K. Le Guin', 1929);
INSERT INTO authors (name, birth_year) VALUES ('Zora Neale Hurston', 1891);
INSERT INTO books (title, genre, year_published) VALUES ('Beloved', 'Fiction', 1987);
INSERT INTO books (title, genre, year_published) VALUES ('Nineteen Eighty Four', 'Fiction', 1949);
INSERT INTO books (title, genre, year_published) VALUES ('Go Tell It on the Mountain', 'Fiction', 1953);
INSERT INTO books (title, genre, year_published) VALUES ('Kindred', 'Science Fiction', 1979);
INSERT INTO books (title, genre, year_published) VALUES ('The Left Hand of Darkness', 'Science Fiction', 1969);
INSERT INTO books (title, genre, year_published) VALUES ('Their Eyes Were Watching God', 'Fiction', 1937);
INSERT INTO books (title, genre, year_published) VALUES ('Animal Farm', 'Satire', 1945);
INSERT INTO books (title, genre, year_published) VALUES ('Parable of the Sower', 'Science Fiction', 1993);""",
"hints": [
"Text values must be wrapped in single quotes: 'like this'.",
"If you see 'NOT NULL constraint failed', you forgot a required column.",
"The semicolon is the statement terminator — don't forget it.",
],
"reflection": [
"What error do you get when you omit a NOT NULL column?",
"Why don't we supply the 'id' value ourselves?",
"What would happen if two INSERT statements had the same id?",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (1, 'Toni Morrison', 1931);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (2, 'George Orwell', 1903);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (3, 'James Baldwin', 1924);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (4, 'Octavia Butler', 1947);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (5, 'Ursula K. Le Guin', 1929);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (6, 'Zora Neale Hurston', 1891);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (1, 'Beloved', 'Fiction', 1987);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (2, 'Nineteen Eighty Four', 'Fiction', 1949);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (3, 'Go Tell It on the Mountain', 'Fiction', 1953);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (4, 'Kindred', 'Science Fiction', 1979);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (5, 'The Left Hand of Darkness', 'Science Fiction', 1969);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (6, 'Their Eyes Were Watching God', 'Fiction', 1937);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (7, 'Animal Farm', 'Satire', 1945);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (8, 'Parable of the Sower', 'Science Fiction', 1993);",
],
},
{
"id": 4,
"title": "Querying Data",
"concept": "SELECT, FROM, WHERE",
"intro": """\
Exercise 4 — Querying Data
SELECT is the most important SQL statement. It reads data from a table
without changing anything.
Syntax:
SELECT col1, col2 FROM table_name;
SELECT col1, col2 FROM table_name WHERE condition;
SELECT * FROM table_name; -- * means "all columns"
The WHERE clause filters which rows are returned. Only rows where the
condition is TRUE are included in the result.""",
"tasks": [
"Select all columns from the books table.",
"Select only the title and genre columns from books.",
"Select books published after 1950.",
"Select authors born before 1920.",
"Select a specific author by name (pick any author from Exercise 3).",
],
"example_sql": """\
-- All books
SELECT * FROM books;
-- Only title and genre
SELECT title, genre FROM books;
-- Books published after 1950
SELECT title, year_published FROM books WHERE year_published > 1950;
-- Authors born before 1920
SELECT name, birth_year FROM authors WHERE birth_year < 1920;
-- A specific author
SELECT * FROM authors WHERE name = 'Toni Morrison';""",
"hints": [
"Use single quotes around text values in WHERE: WHERE name = 'Orwell'",
"SELECT * is convenient but in real apps you usually name each column.",
"SQL is case-insensitive for keywords: SELECT = select = Select.",
"Column names and table names ARE case-sensitive in SQLite.",
],
"reflection": [
"What is the difference between SELECT * and SELECT title, genre?",
"Why should you prefer named columns over * in production code?",
"What happens if the WHERE condition matches no rows?",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (1, 'Toni Morrison', 1931);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (2, 'George Orwell', 1903);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (3, 'James Baldwin', 1924);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (4, 'Octavia Butler', 1947);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (5, 'Ursula K. Le Guin', 1929);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (6, 'Zora Neale Hurston', 1891);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (1, 'Beloved', 'Fiction', 1987);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (2, 'Nineteen Eighty Four', 'Fiction', 1949);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (3, 'Go Tell It on the Mountain', 'Fiction', 1953);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (4, 'Kindred', 'Science Fiction', 1979);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (5, 'The Left Hand of Darkness', 'Science Fiction', 1969);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (6, 'Their Eyes Were Watching God', 'Fiction', 1937);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (7, 'Animal Farm', 'Satire', 1945);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (8, 'Parable of the Sower', 'Science Fiction', 1993);",
],
},
{
"id": 5,
"title": "Filtering and Sorting",
"concept": "WHERE operators, ORDER BY, LIMIT",
"intro": """\
Exercise 5 — Filtering and Sorting
You can combine multiple conditions in WHERE using AND / OR, and use ORDER BY
to sort results. LIMIT caps how many rows are returned.
Comparison operators: = != > >= < <=
Pattern matching: LIKE (% matches any sequence, _ matches one character)
Examples:
WHERE genre = 'Fiction'
WHERE year_published BETWEEN 1940 AND 1960
WHERE title LIKE '%the%' -- title contains "the"
WHERE genre IS NULL -- genre has no value""",
"tasks": [
"Select all Fiction books, sorted by year_published (newest first).",
"Select the 3 most recently published books.",
"Find all books whose title contains the word 'the' (case-insensitive).",
"Find authors born between 1900 and 1930.",
"Select books that are either 'Fiction' OR 'Satire'.",
],
"example_sql": """\
-- Fiction books sorted newest first
SELECT title, year_published
FROM books
WHERE genre = 'Fiction'
ORDER BY year_published DESC;
-- 3 most recent books
SELECT title FROM books ORDER BY year_published DESC LIMIT 3;
-- Titles containing "the" (LIKE is case-insensitive in SQLite by default for ASCII)
SELECT title FROM books WHERE title LIKE '%the%';
-- Authors born 1900–1930
SELECT name, birth_year FROM authors
WHERE birth_year >= 1900 AND birth_year <= 1930
ORDER BY birth_year;
-- Fiction or Satire
SELECT title, genre FROM books WHERE genre = 'Fiction' OR genre = 'Satire';""",
"hints": [
"DESC = descending (highest first). ASC = ascending (lowest first, the default).",
"LIMIT always comes after ORDER BY.",
"LIKE '%word%' — the % signs are wildcards meaning 'anything here'.",
"AND has higher precedence than OR; use parentheses when mixing them.",
],
"reflection": [
"What is the difference between ORDER BY year ASC and ORDER BY year DESC?",
"What does LIMIT do when fewer rows match than the limit?",
"When would you use LIKE instead of =?",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (1, 'Toni Morrison', 1931);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (2, 'George Orwell', 1903);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (3, 'James Baldwin', 1924);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (4, 'Octavia Butler', 1947);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (5, 'Ursula K. Le Guin', 1929);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (6, 'Zora Neale Hurston', 1891);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (1, 'Beloved', 'Fiction', 1987);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (2, 'Nineteen Eighty Four', 'Fiction', 1949);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (3, 'Go Tell It on the Mountain', 'Fiction', 1953);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (4, 'Kindred', 'Science Fiction', 1979);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (5, 'The Left Hand of Darkness', 'Science Fiction', 1969);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (6, 'Their Eyes Were Watching God', 'Fiction', 1937);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (7, 'Animal Farm', 'Satire', 1945);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (8, 'Parable of the Sower', 'Science Fiction', 1993);",
],
},
{
"id": 6,
"title": "Updating Records",
"concept": "UPDATE … SET … WHERE",
"intro": """\
Exercise 6 — Updating Records
UPDATE modifies existing rows. Always use a WHERE clause to target only the
rows you want to change.
⚠ WARNING: An UPDATE without WHERE changes EVERY row in the table.
Best practice: write the SELECT first to confirm which rows you'll change,
then write the UPDATE.
Syntax:
UPDATE table_name SET col = new_value WHERE condition;
UPDATE table_name SET col1 = v1, col2 = v2 WHERE condition;""",
"tasks": [
"First SELECT books WHERE id = 2 to see the current title.",
"Fix the title: UPDATE books SET title = 'Nineteen Eighty-Four' WHERE id = 2;",
"SELECT that row again to confirm the change.",
"Set genre = 'Unknown' for any books where genre IS NULL.",
],
"example_sql": """\
-- Step 1: confirm what you are about to change
SELECT id, title FROM books WHERE id = 2;
-- Step 2: make the change
UPDATE books SET title = 'Nineteen Eighty-Four' WHERE id = 2;
-- Step 3: verify
SELECT id, title FROM books WHERE id = 2;
-- Update all NULL genres
UPDATE books SET genre = 'Unknown' WHERE genre IS NULL;""",
"hints": [
"Always SELECT before UPDATE to confirm which rows will change.",
"IS NULL is the correct syntax — don't write = NULL.",
"You can update multiple columns at once: SET col1 = v1, col2 = v2",
],
"reflection": [
"What would happen if you ran UPDATE books SET genre = 'Fiction'; (no WHERE)?",
"How do you undo an accidental UPDATE in SQLite3?",
"Why is it safer to UPDATE by id rather than by name?",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (1, 'Toni Morrison', 1931);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (2, 'George Orwell', 1903);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (3, 'James Baldwin', 1924);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (4, 'Octavia Butler', 1947);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (5, 'Ursula K. Le Guin', 1929);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (6, 'Zora Neale Hurston', 1891);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (1, 'Beloved', 'Fiction', 1987);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (2, 'Nineteen Eighty Four', 'Fiction', 1949);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (3, 'Go Tell It on the Mountain', 'Fiction', 1953);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (4, 'Kindred', 'Science Fiction', 1979);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (5, 'The Left Hand of Darkness', 'Science Fiction', 1969);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (6, 'Their Eyes Were Watching God', 'Fiction', 1937);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (7, 'Animal Farm', 'Satire', 1945);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (8, 'Parable of the Sower', 'Science Fiction', 1993);",
],
},
{
"id": 7,
"title": "Deleting Records",
"concept": "DELETE FROM … WHERE",
"intro": """\
Exercise 7 — Deleting Records
DELETE removes rows from a table permanently (unless you are in a transaction
you can roll back). Just like UPDATE, always use WHERE.
⚠ DELETE FROM table_name; ← deletes EVERY row — use with extreme caution.
The recommended workflow:
1. SELECT to see what you are about to delete.
2. DELETE with the same WHERE clause.
3. SELECT again to confirm the row is gone.""",
"tasks": [
"Insert a 'bad' book record that you will then delete.",
"SELECT that record to confirm it exists.",
"DELETE it using its id.",
"SELECT again to confirm it is gone.",
],
"example_sql": """\
-- Insert a bad record
INSERT INTO books (title, genre, year_published) VALUES ('Bad Test Record', 'Test', 2000);
-- Check it was created (note its id)
SELECT * FROM books ORDER BY id DESC LIMIT 3;
-- Delete it (replace 9 with the actual id you saw)
DELETE FROM books WHERE id = 9;
-- Confirm it is gone
SELECT * FROM books ORDER BY id DESC LIMIT 3;""",
"hints": [
"Use SELECT first — confirm the exact id before you DELETE.",
"There is no UNDO in SQLite3 once you commit. Be careful!",
"DELETE only removes rows; the table itself remains.",
],
"reflection": [
"What is the difference between DELETE FROM books WHERE id=5 and DROP TABLE books?",
"Why is it safer to delete by id rather than by name or title?",
"What is a transaction, and how could it protect you from accidental deletes?",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (1, 'Toni Morrison', 1931);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (2, 'George Orwell', 1903);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (3, 'James Baldwin', 1924);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (4, 'Octavia Butler', 1947);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (5, 'Ursula K. Le Guin', 1929);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (6, 'Zora Neale Hurston', 1891);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (1, 'Beloved', 'Fiction', 1987);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (2, 'Nineteen Eighty-Four', 'Fiction', 1949);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (3, 'Go Tell It on the Mountain', 'Fiction', 1953);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (4, 'Kindred', 'Science Fiction', 1979);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (5, 'The Left Hand of Darkness', 'Science Fiction', 1969);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (6, 'Their Eyes Were Watching God', 'Fiction', 1937);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (7, 'Animal Farm', 'Satire', 1945);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (8, 'Parable of the Sower', 'Science Fiction', 1993);",
],
},
{
"id": 8,
"title": "Primary Keys and Uniqueness",
"concept": "PRIMARY KEY, AUTOINCREMENT, UNIQUE constraint",
"intro": """\
Exercise 8 — Primary Keys and Uniqueness
A PRIMARY KEY uniquely identifies every row. A UNIQUE constraint prevents
duplicate values in a column even if it is not the primary key.
Surrogate key: an artificial id column (usually AUTOINCREMENT).
Natural key: a real-world value (email, ISBN, etc.).
Surrogate keys are preferred because:
• Natural keys can change (people change email addresses).
• Natural keys may not exist for every row.
• Integer comparisons are faster than string comparisons.""",
"tasks": [
"Create a 'members' table with a UNIQUE email column.",
"Insert two members with different emails — this should succeed.",
"Try inserting two members with the same email — observe the error.",
"Use .schema members to inspect the constraint.",
],
"example_sql": """\
CREATE TABLE members (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT UNIQUE NOT NULL,
name TEXT NOT NULL
);
-- These should both succeed
INSERT INTO members (email, name) VALUES ('alice@example.com', 'Alice');
INSERT INTO members (email, name) VALUES ('bob@example.com', 'Bob');
-- This should fail with UNIQUE constraint error
INSERT INTO members (email, name) VALUES ('alice@example.com', 'Alice Again');
-- Inspect the table
SELECT * FROM members;""",
"hints": [
"The error for a duplicate unique value is: UNIQUE constraint failed",
"AUTOINCREMENT guarantees ids are never reused, even after deletes.",
"A table can have only one PRIMARY KEY but many UNIQUE columns.",
],
"reflection": [
"Why use an id column instead of email as the primary key?",
"What would happen to existing data if you added UNIQUE to an existing column that already has duplicates?",
"Name a real-world example where a natural key makes sense.",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (1, 'Toni Morrison', 1931);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (2, 'George Orwell', 1903);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (3, 'James Baldwin', 1924);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (4, 'Octavia Butler', 1947);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (5, 'Ursula K. Le Guin', 1929);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (6, 'Zora Neale Hurston', 1891);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (1, 'Beloved', 'Fiction', 1987);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (2, 'Nineteen Eighty-Four', 'Fiction', 1949);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (3, 'Go Tell It on the Mountain', 'Fiction', 1953);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (4, 'Kindred', 'Science Fiction', 1979);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (5, 'The Left Hand of Darkness', 'Science Fiction', 1969);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (6, 'Their Eyes Were Watching God', 'Fiction', 1937);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (7, 'Animal Farm', 'Satire', 1945);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (8, 'Parable of the Sower', 'Science Fiction', 1993);",
],
},
{
"id": 9,
"title": "Aggregate Functions",
"concept": "COUNT, SUM, AVG, MIN, MAX",
"intro": """\
Exercise 9 — Aggregate Functions
Aggregate functions compute a single summary value from a set of rows.
COUNT(*) — total number of rows
COUNT(column) — rows where column is not NULL
SUM(column) — sum of all values
AVG(column) — arithmetic mean
MIN(column) — smallest value
MAX(column) — largest value
You can use AS to give the result a readable name:
SELECT COUNT(*) AS total_books FROM books;""",
"tasks": [
"Count the total number of books in the library.",
"Find the average birth year of all authors.",
"Find the earliest and latest year_published in books.",
"Count how many books have a non-NULL genre.",
"Challenge: count how many books are in each genre. (Hint: see Exercise 10)",
],
"example_sql": """\
-- Total books
SELECT COUNT(*) AS total_books FROM books;
-- Average author birth year
SELECT AVG(birth_year) AS avg_birth_year FROM authors;
-- Year range of books
SELECT MIN(year_published) AS earliest,
MAX(year_published) AS latest
FROM books;
-- Books with a non-NULL genre
SELECT COUNT(genre) AS books_with_genre FROM books;""",
"hints": [
"COUNT(*) counts all rows including NULLs; COUNT(col) skips NULLs.",
"AVG ignores NULL values automatically.",
"You can use AS to rename any column in the result set.",
],
"reflection": [
"What is the difference between COUNT(*) and COUNT(genre)?",
"What would AVG return if all values in the column were NULL?",
"When would you use SUM versus COUNT?",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (1, 'Toni Morrison', 1931);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (2, 'George Orwell', 1903);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (3, 'James Baldwin', 1924);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (4, 'Octavia Butler', 1947);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (5, 'Ursula K. Le Guin', 1929);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (6, 'Zora Neale Hurston', 1891);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (1, 'Beloved', 'Fiction', 1987);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (2, 'Nineteen Eighty-Four', 'Fiction', 1949);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (3, 'Go Tell It on the Mountain', 'Fiction', 1953);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (4, 'Kindred', 'Science Fiction', 1979);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (5, 'The Left Hand of Darkness', 'Science Fiction', 1969);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (6, 'Their Eyes Were Watching God', 'Fiction', 1937);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (7, 'Animal Farm', 'Satire', 1945);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (8, 'Parable of the Sower', 'Science Fiction', 1993);",
],
},
{
"id": 10,
"title": "Grouping Data",
"concept": "GROUP BY, HAVING",
"intro": """\
Exercise 10 — Grouping Data
GROUP BY collapses multiple rows that share the same value into one group, so
you can compute aggregates per group (e.g. count per genre).
HAVING is the GROUP BY equivalent of WHERE. Key distinction:
WHERE — filters individual rows BEFORE grouping
HAVING — filters groups AFTER grouping (can reference aggregate functions)
Typical pattern:
SELECT col, COUNT(*) AS n
FROM table
WHERE <optional row filter>
GROUP BY col
HAVING n > 1
ORDER BY n DESC;""",
"tasks": [
"Count the number of books in each genre.",
"Show only genres that have more than 1 book.",
"Find the oldest author birth year per first letter of their name. (challenge)",
"Count books published per decade using year_published / 10 * 10.",
],
"example_sql": """\
-- Books per genre
SELECT genre, COUNT(*) AS total
FROM books
GROUP BY genre
ORDER BY total DESC;
-- Only genres with more than 1 book
SELECT genre, COUNT(*) AS total
FROM books
GROUP BY genre
HAVING total > 1;
-- Books per decade
SELECT (year_published / 10) * 10 AS decade,
COUNT(*) AS total
FROM books
GROUP BY decade
ORDER BY decade;""",
"hints": [
"Every column in SELECT must either be in GROUP BY or wrapped in an aggregate.",
"HAVING comes after GROUP BY and before ORDER BY.",
"You can GROUP BY an expression, not just a column name.",
],
"reflection": [
"Why can't you use WHERE to filter on COUNT(*)?",
"What does GROUP BY do when there are NULL values in the grouped column?",
"Write the query without GROUP BY. What do you get? Why is GROUP BY needed?",
],
"setup": [
"""CREATE TABLE IF NOT EXISTS authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birth_year INTEGER
);""",
"""CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
genre TEXT,
year_published INTEGER
);""",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (1, 'Toni Morrison', 1931);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (2, 'George Orwell', 1903);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (3, 'James Baldwin', 1924);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (4, 'Octavia Butler', 1947);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (5, 'Ursula K. Le Guin', 1929);",
"INSERT OR IGNORE INTO authors (id, name, birth_year) VALUES (6, 'Zora Neale Hurston', 1891);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (1, 'Beloved', 'Fiction', 1987);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (2, 'Nineteen Eighty-Four', 'Fiction', 1949);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (3, 'Go Tell It on the Mountain', 'Fiction', 1953);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (4, 'Kindred', 'Science Fiction', 1979);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (5, 'The Left Hand of Darkness', 'Science Fiction', 1969);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (6, 'Their Eyes Were Watching God', 'Fiction', 1937);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (7, 'Animal Farm', 'Satire', 1945);",
"INSERT OR IGNORE INTO books (id, title, genre, year_published) VALUES (8, 'Parable of the Sower', 'Science Fiction', 1993);",
],
},
{
"id": 11,
"title": "Joins",
"concept": "Foreign keys, INNER JOIN, LEFT JOIN",
"intro": """\
Exercise 11 — Joins
A foreign key is a column in one table that references the primary key of
another table. Joins combine rows from two tables based on a matching column.
INNER JOIN — returns only rows where the match exists in BOTH tables.
LEFT JOIN — returns ALL rows from the left table; right-side columns are NULL
when no match exists.
We will link each book to its author by adding an author_id column to books
(using ALTER TABLE), then populate it, then write join queries.""",
"tasks": [
"Add an author_id column to the books table.",
"Update books to set their author_id (see examples).",
"Write an INNER JOIN to show each book title with its author name.",
"Write a LEFT JOIN to find books that have no author assigned yet.",
],
"example_sql": """\
-- Add the foreign key column
ALTER TABLE books ADD COLUMN author_id INTEGER;
-- Link books to authors by id
UPDATE books SET author_id = 1 WHERE title = 'Beloved';
UPDATE books SET author_id = 2 WHERE title LIKE '%Eighty%';
UPDATE books SET author_id = 3 WHERE title LIKE '%Mountain%';
UPDATE books SET author_id = 4 WHERE title = 'Kindred';
UPDATE books SET author_id = 4 WHERE title LIKE '%Sower%';
UPDATE books SET author_id = 5 WHERE title LIKE '%Darkness%';
UPDATE books SET author_id = 6 WHERE title LIKE '%Watching%';
UPDATE books SET author_id = 2 WHERE title = 'Animal Farm';
-- INNER JOIN: only books that have an author
SELECT books.title, authors.name AS author
FROM books
INNER JOIN authors ON books.author_id = authors.id;
-- LEFT JOIN: all books, NULLs where no author is linked
SELECT books.title, authors.name AS author
FROM books
LEFT JOIN authors ON books.author_id = authors.id;
-- Find books with no author assigned
SELECT books.title
FROM books
LEFT JOIN authors ON books.author_id = authors.id
WHERE authors.id IS NULL;""",
"hints": [
"SQLite allows adding columns with ALTER TABLE ADD COLUMN.",
"After ALTER TABLE, run .schema books to see the new column.",
"In a JOIN query, prefix ambiguous column names: books.id, authors.id.",
"LEFT JOIN keeps all rows from the left (first) table.",
],
"reflection": [