MySQL Forums
Forum List  »  Newbie

get the latest semester of each course in table
Posted by: Dori Goor
Date: June 03, 2019 11:30PM

Hi

i have a table named "courses" that looks like this:
--------------
id, shortname
--------------
3, 20115-2019a
4, 10112-2018a
5, 20115-2019b
6, 10112-2020a
7, 43112-2017a

the last part of the "shortname" field represts a semester. ("2019a", "2018a" etc.)
the number ("20115", "10112" etc.) is the course name.

I need an sql query that will get my the record with the laster semester of each course.

in the above example I want to the result to be:
3, 20115-2019b (because 2019b is the latest semester of 20115)
6, 10112-2020a (because 2020a is the latest semester of 10112)
7, 43112-2017a (because 2017a is the latest semester of 43112)

this is what I tried so far:
SELECT id, MAX(shortname)
FROM courses

it doesn't work, only give me the first record.

Options: ReplyQuote


Subject
Written By
Posted
get the latest semester of each course in table
June 03, 2019 11:30PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.