I have a table(a temporary table which I've created from a long SQL query) in the following format:
Moviename | Actorname | Actorage
-----------------------------------
m1 | a1 | 5
m1 | a2 | 10
m1 | a3 | 15
m2 | a1 | 10
m2 | a4 | 20
m3 | a5 | 35
I would like to find this:
For every movie in my temporary table, I want to find the oldest actor. However, the aggregation won't let me.
What I've tried so far:
Select
Moviename,
Actorname,
Max(Actorage)
From TempTable
Group By Moviename
The SQL query above tells me that I need to have Actorname in the group by statement. I know that for SQL to compile and execute the code, apart from the aggregation, all attributes must be grouped by.
I want the following result:
m1 | a3 | 15
m2 | a4 | 20
m3 | a5 | 35