Return 0 for no matches, rather than nothing
Posted: Sun Aug 10, 2008 3:58 pm
I'm just wondering if this can be done in MySQL, because I feel it probably is possible, but I just don't know what to search for.
As an example, if I've got a query like this:
It might only return one row (which when print_r()'ed could look like this):
But what about if I want to return an array like this:
Is that possible? I know I could fool around with the array in PHP and get it like that, but it just seems like extra hassle.
Even if that isn't possible, is it possible to run a query in MySQL to just fetch every date between 2 dates?
Thanks.
As an example, if I've got a query like this:
Code: Select all
SELECT
DATE_FORMAT(`time_ordered`, '%d/%m/%y') AS `date`,
SUM(`total_price`) AS `total_takings`
FROM
`orders`
WHERE
`completed` = 'Y'
AND
`time_ordered`
BETWEEN
'2008-07-07'
AND
'2008-08-01'
GROUP BY
YEAR(`time_ordered`) AND DAYOFYEAR(`time_ordered`)Code: Select all
Array ( [0] => Array ( [date] => 08/07/08 [total_takings] => 129.00 ) )Code: Select all
Array (
[0] => Array ( [date] => 07/07/08 [total_takings] => 0.00 ),
[1] => Array ( [date] => 08/07/08 [total_takings] => 129.00 ),
[2] => Array ( [date] => 09/07/08 [total_takings] => 0.00 ),
[3] => Array ( [date] => 10/07/08 [total_takings] => 0.00 ),
[4] => Array ( [date] => 11/07/08 [total_takings] => 0.00 ),
... etc, etc through to the max BETWEEN clause...
)Even if that isn't possible, is it possible to run a query in MySQL to just fetch every date between 2 dates?
Thanks.