-2

I am using Oracle SQL Developer and I am trying to pick the first entry of the student population. So, that I have one row for each ID.

ID DEGREE AWARDED ACADEMIC PERIOD
147 GR MS 2022
147 UG BS 2020
170 GR MA 2023
170 UG BA 2018

Expected output is

ID DEGREE AWARDED ACADEMIC PERIOD
147 GR MS 2022
170 GR MA 2023
2
  • WHERE ROW_NUMBER() = 1
    – Akina
    Oct 2, 2023 at 17:25
  • What if there's a tie - the same ACADEMIC PERIOD more than once for the same ID?...is this possible and if so, how do you want it handled?
    – J.D.
    Oct 3, 2023 at 12:05

1 Answer 1

0
FROM StudentDegrees sd
WHERE ACADEMIC_PERIOD = (
    SELECT MIN(ACADEMIC_PERIOD)
    FROM StudentDegrees
    WHERE ID = sd.ID
);

This should workout

2
  • I think by "first" OP means the latest ACADEMIC PERIOD. So I believe you want to use MAX() actually.
    – J.D.
    Oct 2, 2023 at 16:58
  • @J.D., I have used the query to get the order ascendingly; However, if the output is not the one he desires, he can use MAX(). Oct 3, 2023 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.