Classic Student-Enrollment-Course structure, but the Enrollment join table has an additional DATE column. Here's a sample fiddle: http://sqlfiddle.com/#!9/81d3e5/3.
CREATE TABLE student (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL
);
CREATE TABLE course (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL
);
CREATE TABLE enrollment (
student_id INT NOT NULL,
course_id INT NOT NULL,
enrollment_date DATE NOT NULL,
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES student(id),
FOREIGN KEY (course_id) REFERENCES course(id)
);
INSERT INTO student (name) VALUES
("Alice"),
("Bob");
INSERT INTO course (name) VALUES
("CS 101"),
("Relational Algebra"),
("Compilers");
INSERT INTO enrollment (student_id, course_id, enrollment_date) VALUES
(1, 1, '2020-01-13'),
(1, 2, '2020-02-05'),
(2, 2, '2020-02-07');
A student needs to see a list of all available courses, and if they're enrolled, the enrollment date. Here's the desired result for student ID 2:
+--------------------+-----------------+
| course_name | enrollment_date |
+--------------------+-----------------+
| CS 101 | null |
| Relational Algebra | 2020-02-07 |
| Compilers | null |
+--------------------+-----------------+
It's been a few years since I did anything more complicated than a simple left join, and I can't figure this one out.