I want my code to gather grades-table with students-table with a STUDENT_ID
as common factor. With the DISTINCT
clause, it removes row duplicates, but I want it to not show the same PERSON_ID
more than once, so it will only show each STUDENT_ID
once.
It's a huge datafile.
SELECT DISTINCT
grades.PERSON_ID, grades.GRADE,
students.PERSON_ID, students.ENROLL_PERIOD
FROM
students
INNER JOIN
grades ON students.PERSON_ID = grades.PERSON_ID
WHERE
ENROLL_PERIOD < 132
ORDER BY
students.ENROLL_PERIOD
SAMPLE From before -> STUDENTS:
PERSON_ID PROGRAM_ID ENROLL_PERIOD
12401 82 109
12401 4549 112
720921 5921 112
832521 9981 114
SAMPLE From before -> GRADES:
PERSON_ID GRADE GRADE_DATE GRADE_TYPE
2308133 7 16-06-26 p
2308133 10 18-01-24 p
2308133 4 16-02-01 p
SAMPLE from when the 2 tables are combined, it looks like this:
PERSON_ID GRADE PERSON_ID ENROLL_PERIOD
12401 00 12401 109
12401 02 12401 112
720921 00 720921 112
832521 00 832521 114
Here we see, that the "12401" row is there twice, since it's only if the whole row is different It should skip the 2nd "12401" and jump to the next one ( For instance 12491)
PERSON_ID GRADE PERSON_ID ENROLL_PERIOD
12401 00 12401 109
720921 00 720921 112
832521 00 832521 114