I have the following table structure/data:
|id||date (DATE)||hour (INT)||tally (INT)||sum (INT)|
With the following query:
SELECT * FROM `table` WHERE ((`date` >= '2023-05-15') AND (`hour` >= '4')) AND ((`date` <= '2023-05-16') AND (`hour` <= '4')) ORDER BY `id` DESC LIMIT 0,1000;
My expectation is that the data in the example is returned. I have two discrete where conditions (parenthesised). Instead when I run the query no data is returned.
Could anyone point out why the data is not being returned?
What you’d need is this:
SELECT * FROM `table` WHERE ( (`date` = '2023-05-15' AND `hour` >= '4') OR (`date` > '2023-05-15') ) AND ( (`date` = '2023-05-16' AND `hour` <= '4') OR (`date` < '2023-05-16') ) ORDER BY `id` DESC LIMIT 0,1000
Which is why you should never keep the date and time components separately.
It’as like storing