I have 2 tables in my database that I want to merge into one with a join table:
plan:
| id | c_project | plan | date |
|---|---|---|---|
| 1 | P001 | 20 | 2021-12-25 |
| 2 | P001 | 25 | 2022-01-07 |
actual:
| id | c_project | actual | date |
|---|---|---|---|
| 1 | P001 | 30 | 2021-12-25 |
| 2 | P001 | 35 | 2022-01-07 |
My JOIN table query:
SELECT a.`p_code`, plan, actual, a.`date`
FROM plan AS a
JOIN actual AS b
ON a.`p_code` = b.`p_code`
GROUP BY a.`p_code`, a.`date`
ORDER BY a.`date` ASC
I have a problem with the output generated, that the actual data in the actual table is only the first date period that is displayed:
| id | c_project | plan | actual | date |
|---|---|---|---|---|
| 1 | P001 | 20 | 30 | 2021-12-25 |
| 2 | P001 | 25 | 30 | 2022-01-07 |
How can I do to improve my query above to get output like this:
| id | c_project | plan | actual | date |
|---|---|---|---|---|
| 1 | P001 | 20 | 30 | 2021-12-25 |
| 2 | P001 | 25 | 35 | 2022-01-07 |