I have two tables.
Table 1:
+---------+---------+
| Lead_ID | Deal_ID |
+---------+---------+
| 2323 | null |
| 2324 | 1199 |
| 2325 | null |
| 2326 | null |
| 2327 | 1080 |
+---------+---------+
Table 2:
+---------+-------------+-------------+------------+
| Deal_ID | Stage_From | Stage_To | ChangeDate |
+---------+-------------+-------------+------------+
| 1199 | incoming | stage1 | 01-Dec-14 |
| 1199 | stage1 | incoming | 05-Dec-14 |
| 1199 | incoming | stage1 | 12-Dec-14 |
| 1080 | incoming | unqualified | 06-Dec-14 |
| 1080 | unqualified | stage2 | 07-Dec-14 |
I would like to add the "ChangeDate" for each Deal_ID that has a record in Table 2 where the Stage Changed from "Incoming" to "Stage1". In cases where the stage changed from "incoming" to "stage1" multiple times, I want to maximum date i.e. December 12, 2014 in the example rather than December 1, 2014.
Resulting Table should be:
+---------+---------+------------+
| Lead_ID | Deal_ID | ChangeDate |
+---------+---------+------------+
| 2323 | null | null |
| 2324 | 1199 | 12-Dec-14 |
| 2325 | null | null |
| 2326 | null | null |
| 2327 | 1080 | null |
+---------+---------+------------+
I looked at a few similar questions which recommend using "Group_Concat", but I can't get to what I want with that method.
Any suggestions are greatly appreciated.