How get null result if not found in Mysql |
Hi,
I need to select all orders for last week. Actually for 2022-01-12,2022-01-11,2022-01-10,2022-01-09,2022-01-08,2022-01-07,2022-01-06 But I have orders only for 2022-01-11,2022-01-10,2022-01-09 and I need to other date record event no I try to join to order on a date but not working Please help me with that Thanks
@omid_student ,
Please show us the SQL that you are using to create the results. More then likely it is how your tables are joined. Also, if possible give us a view of how you wish the results to appear.
(01-12-2022, 07:33 AM)php_rocs Wrote: @omid_student , SELECT * FROM tbl_order WHERE DATE(order_date) IN ('2021-01-01','2021-01-02','2021-01-03','2021-01-04','2021-01-05') GROUP BY DATE(order_date) This query return only '2021-01-03','2021-01-04' date but I need to all date value event zero or null I don't want to do it with PHP
@omid_student ,
Does the other dates appear in another list or query? Are there any records associated with the missing dates? Your query is giving you exactly what you are asking for. It needs to be rewritten.
(01-12-2022, 12:16 PM)php_rocs Wrote: @omid_student , I need to associate date in query not only records that exist If the query does not return all date results, I have to set 0 to each date in PHP and that is not a good way
SELECT * FROM tbl_order WHERE DATE(order_date) IN ('2021-01-01','2021-01-02','2021-01-03','2021-01-04','2021-01-05') OR order_date IS NULL GROUP BY DATE(order_date)
|
Welcome Guest, Not a member yet? Register Sign In |