Table: t_cost
+------------+-----+-----+------+
| DateActive | TID | WID | Cost |
+------------+-----+-----+------+
| 2021-05-01 | 1 | 1 | 5.05 | --->
| 2021-05-01 | 1 | 2 | 5.08 | |
| 2021-05-01 | 2 | 1 | 5.10 | |
| 2021-05-01 | 2 | 2 | 6.00 | |
| 2021-05-08 | 1 | 1 | 5.10 | <-- New Cost
+------------+-----+-----+------+
TID and WID are a unique combination but I can't make the table UNIQUE as I need to hold historical costs.
I have tried many a combination including sub queries but this is where I am at.
SELECT MAX(DateActive) AS DateActive,Cost,TID,WID FROM t_cost GROUP BY TID,WID
The result from this is:
+------------+-----+-----+------+
| DateActive | TID | WID | Cost |
+------------+-----+-----+------+
| 2021-05-08 | 1 | 1 | 5.05 | <-- should be 5.10
| 2021-05-01 | 1 | 2 | 5.08 |
| 2021-05-01 | 2 | 1 | 5.10 |
| 2021-05-01 | 2 | 2 | 6.00 |
+------------+-----+-----+------+
Do you know how to select the latest date using the unique combination of TID and WID?
Result required:
+------------+-----+-----+------+
| DateActive | TID | WID | Cost |
+------------+-----+-----+------+
| 2021-05-08 | 1 | 1 | 5.10 | <--
| 2021-05-01 | 1 | 2 | 5.08 |
| 2021-05-01 | 2 | 1 | 5.10 |
| 2021-05-01 | 2 | 2 | 6.00 |
+------------+-----+-----+------+
Thank you