I’m not sure how to write this query in SQL. there are two tables
**GroupRecords** Id (int, primary key) Name (nvarchar) SchoolYear (datetime) RecordDate (datetime) IsUpdate (bit) **People** Id (int, primary key) GroupRecordsId (int, foreign key to GroupRecords.Id) Name (nvarchar) Bio (nvarchar) Location (nvarchar)
return a distinct list of people who belong to GroupRecords that have a SchoolYear of ‘2000’. In the returned list, people.name should be unique (no duplicate People.Name), in case of a duplication only the person who belong to the GroupRecords with the later RecordDate should be returned.
It would probably be better to write a stored procedure for this right?
This is untested, but it should do what is required in the question.
It selects all details about the person.
The subquery will make it match only the latest RecordDate for a single name. It will also look only in the right GroupRecord because of the Match between the ids.