I am trying to retrieve a column value in T-SQL from a query with an aggregate function:
I am looking for the program no. with the most recent starting date.
I am working with this table (simplified):
ID | ProgramNo | StartDate | Course
1 | 10 | 2009-01-01 | CIS101
2 | 11 | 2009-02-01 | CIS102
3 | 12 | 2009-03-01 | CIS103
4 | 12 | 2009-03-01 | ACCT101
SELECT MAX (StartDate), ProgramNo
This is throwing out an error: ProgramNo is not part of the aggregate function or a GROUP BY clause.
I have also looked into the TOP function, with the same result.
Both of them complain that no other column can be part of the query.
How is it possible to get the program no in an efficient way?