Many-to-Many Relationship in SQL — a practical guide to SQL many-to-many relationship with clear examples you can reuse in real projects.
SQL Tutorial Series (81/100). Prefer one article? Read the complete SQL tutorial.
Short description
Add payload columns (e.g., enrolled_at) on the junction when needed.
M:N sketch
CREATE TABLE course_user (
course_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
enrolled_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (course_id, user_id)
);