I have two different tables, my first table contains the authorizations granted to other requests. It has the following columns:
Authorizations table
| authorization_date | role_id | request_id |
|--------------------|---------|------------|
| 2011-08-02 | 1 | 168 |
| 2011-08-10 | 2 | 168 |
| 2011-08-20 | 6 | 168 |
| 2011-08-03 | 2 | 169 |
| 2011-08-24 | 6 | 169 |
| 2011-08-05 | 3 | 170 |
| 2011-08-09 | 5 | 170 |
As you can see, different people have different roles and also can grant a certain level of authorization. The higher the role, the higher the request has been processed.
Now, what I want to do is I want to show the description associated to the role_id (which is in another table) and ONLY the last authorization. Since I have the date for it I already know which one is the latest one. However I don’t know how to do this as I try to group my query by getting the maximum value of the date, when I link it to my second table containing only the description of the role_id, I get duplicates and I just can’t think of a way to do this, I’m kind of new with queries & as I’ve been learning by myself I don’t know many things. Any ideas?
Thanks!
I am guessing a little here, but I think you want:
The derived table will get the maximum authorization date for each request. Then you can join to get the role_id for that request and join again to get the description.