I am attempting to join two tables while pulling the max date from one. I have a student table and a communication table. Each student is unique in the student table and has many communication entries.
I would like to create a SQL script that pulls each student's ID, name, latest communication date, and the communication message for that date.
I am able to pull the latest date for each student using max(comm_date)
and group by
, but things get messy (many duplications) when pulling the corresponding communication message.
Table: Student
studentid, name
Table: Communications
studentid, comm_date, comm_msg
Result:
student.studentid, student.name, communications.comm_date, communications.comm_msg
How can I pull the corresponding communication message given max(comm_date)
?