Table: A
| ID | Name |
| -- | ------- |
| 1 | John |
| 2 | Micheal |
| 3 | Mary |
Table B:
| ID | Date | Bonus |
| -- | -------- | ----- |
| 1 | 01/01/09 | 1200 |
| 1 | 01/07/12 | 4000 |
| 1 | 12/05/14 | 2500 |
| 3 | 01/01/09 | 0 |
| 3 | 11/10/17 | 1850 |
| 2 | 08/01/16 | 2500 |
| ... | ... | ... |
I have these 2 tables. My goal to write a query that retreives the name, the lastest date available for that person and the bonus coresponding to both that date and that name.
Here's the code I have,
SELECT NAME, date_max, BONUS FROM
((SELECT A.ID, MAX(A.DATE) as date_max FROM
table_A A JOIN table_B B
USING (ID)
GROUP BY ID) C
JOIN table_B D
ON (C.ID = D.ID AND date_max = D.DATE))
The problem is that by joining on two conditions (last line) I duplicated the ID column in the result of my inner query and now when I try to execute the outer SELECT I get the invalid identifier error. Please help me fix this