-1

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
Shadow
  • 33,525
  • 10
  • 51
  • 64
Identic 7
  • 37
  • 4
  • Does this answer your question? [Error related to only\_full\_group\_by when executing a query in MySql](https://stackoverflow.com/questions/34115174/error-related-to-only-full-group-by-when-executing-a-query-in-mysql) – philipxy Jul 29 '22 at 10:00
  • [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/3404097) [ask] [Help] [mre] PS Please look at the formatted version of your post before you publish. Please format code reasonably. – philipxy Jul 29 '22 at 10:01
  • 1
    *```ON a.p_code = b.p_code```* No such column in your tables. – Akina Jul 29 '22 at 10:16
  • ```.. FROM plan JOIN actual USING (c_project, date) ..``` ? – Akina Jul 29 '22 at 10:17
  • sorry there was an error in writing, I mean c_project , now my problem has been solved, thanks for the help from everyone. – Identic 7 Jul 30 '22 at 07:11

1 Answers1

0

Please consider join by date columns aswell

SELECT a.`p_code`, plan, actual, a.`date`
   FROM plan AS a 
   JOIN actual AS b
ON a.`p_code` = b.`p_code` and a.`date` = b.`date`
GROUP BY a.`p_code`, a.`date`
ORDER BY a.`date` ASC