-- Create the Students table
CREATE TABLE Students (
student_id INT PRIMARY KEY,
student_name VARCHAR(255)
);
-- Create the Courses table
CREATE TABLE Courses (
course_id INT PRIMARY KEY,
course_name VARCHAR(255)
);
-- Create the StudentCourses junction table
CREATE TABLE StudentCourses (
student_id INT,
course_id INT,
FOREIGN KEY (student_id) REFERENCES Students(student_id),
FOREIGN KEY (course_id) REFERENCES Courses(course_id)
);
-- Insert some data into the tables
INSERT INTO Students (student_id, student_name) VALUES
(1, 'Alice'),
(2, 'Bob'),
(3, 'Charlie');
INSERT INTO Courses (course_id, course_name) VALUES
(101, 'Math'),
(102, 'Science'),
(103, 'History');
INSERT INTO StudentCourses (student_id, course_id) VALUES
(1, 101),
(1, 102),
(2, 102),
(2, 103),
(3, 101);
-- Query to find all courses taken by Alice
SELECT c.course_name
FROM Courses c
JOIN StudentCourses sc ON c.course_id = sc.course_id
JOIN Students s ON sc.student_id = s.student_id
WHERE s.student_name = 'Alice';