Joins
Table Relationships
Real apps split data into several tables and link them with keys, so nothing is stored twice.
| courses.id | courses.title |
|---|---|
| 1 | Python |
| 2 | HTML |
| enrolments.student_id | enrolments.course_id |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 2 | 2 |
enrolments.student_id is a foreign key pointing to students.id, and course_id points to courses.id.
CREATE TABLE enrolments (
student_id INTEGER REFERENCES students(id),
course_id INTEGER REFERENCES courses(id)
);