Hi im tyring to query junction table, but i cant figure it out. how can i find the five students with the highest score in a particular cours
CREATE TABLE Students (
StudentID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
StudentNum int NOT NULL,
);
CREATE TABLE Courses (
CourseID int NOT NULL PRIMARY KEY,
CourseName varchar(255) NOT NULL,
GPA int(255) NOT NULL
);
CREATE TABLE University (
StudentID int NOT NULL,
CourseID int NOT NULL,
CONSTRAINT PK_University PRIMARY KEY
(
StudentID,
CourseID
),
FOREIGN KEY (StudentID) REFERENCES Students (StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses (CourseID)
);
I added the score field to the
Universitytable and change University name toStudents_Courses.First change the University table to :
Now you can
jointhe tables and sort by score and find 5 of the highest scores.you can use
OR
OR use window function
demo in dbfiddle