![]() |
How get null result if not found in Mysql - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How get null result if not found in Mysql (/showthread.php?tid=80992) |
How get null result if not found in Mysql - omid_student - 01-11-2022 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 RE: How get null result if not found in Mysql - php_rocs - 01-12-2022 @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. RE: How get null result if not found in Mysql - omid_student - 01-12-2022 (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 RE: How get null result if not found in Mysql - php_rocs - 01-12-2022 @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. RE: How get null result if not found in Mysql - omid_student - 01-12-2022 (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 RE: How get null result if not found in Mysql - nfaiz - 01-13-2022 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) RE: How get null result if not found in Mysql - omid_student - 01-13-2022 (01-13-2022, 02:01 AM)nfaiz Wrote: 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) Not working and actually that is not logical query |