The results of these queries will return false data because you are not grouping by the column that is the key to join the other table (order id).
Obviously, a second request cannot be dispensed with, but then the algorithm is too complex.
So all this makes no sense, it is better to make one request by grouping by orders.id, and by means of PHP to group by month.
M
Modestas
✓ Link copied!
Sorry, can you expand on this a bit more? It seems that you see a mistake here, but I'm not sure where (this was tested to make sure it works correctly). Would love to see if there's a mistake and improve it!
DS
Dmytro Sakharuk
✓ Link copied!
Execute the query without joining the table and compare the results (order_total, total_orders).
M
Modestas
✓ Link copied!
First of all, thank you for noticing this. It does have an issue if there are more products assigned to the order_products table, and our testing had some flaws in the logic. I will update this article soon with updated solution and possibly test-cases for everyone to ues.
Sorry about this
M
Modestas
✓ Link copied!
Hi, both examples were updated and tests were added for them!
The results of these queries will return false data because you are not grouping by the column that is the key to join the other table (order id). Obviously, a second request cannot be dispensed with, but then the algorithm is too complex. So all this makes no sense, it is better to make one request by grouping by orders.id, and by means of PHP to group by month.
Sorry, can you expand on this a bit more? It seems that you see a mistake here, but I'm not sure where (this was tested to make sure it works correctly). Would love to see if there's a mistake and improve it!
Execute the query without joining the table and compare the results (order_total, total_orders).
First of all, thank you for noticing this. It does have an issue if there are more products assigned to the order_products table, and our testing had some flaws in the logic. I will update this article soon with updated solution and possibly test-cases for everyone to ues.
Sorry about this
Hi, both examples were updated and tests were added for them!
Thank you for noticing this issue.