Welcome Guest, Not a member yet? Register   Sign In
How get null result if not found in Mysql
#1

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
Reply
#2

@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.
Reply
#3

(01-12-2022, 07:33 AM)php_rocs Wrote: @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.

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
Reply
#4

@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.
Reply
#5

(01-12-2022, 12:16 PM)php_rocs Wrote: @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.

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
Reply
#6

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)
Reply
#7

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB