IFNULL

IFNULL

am 14.02.2010 09:01:42 von ron.piggott

How do I add " IFNULL " to the LEFT JOIN query? I either want the result
from the database or a 0 instead of the word NULL

Ron

SELECT `store_product_profile`.`reference` , inventory.inventory,
sold_1.quantity, sold_2.quantity, sold_3.quantity
FROM `store_product_profile`

LEFT JOIN (

SELECT `store_product_inventory_control`.`store_product_profile_ref erence`
, SUM( `store_product_inventory_control`.`quantity` ) AS inventory
FROM `store_product_inventory_control`
GROUP BY `store_product_inventory_control`.`store_product_profile_ref erence`
) AS inventory ON `store_product_profile`.`reference` =
`inventory`.`store_product_profile_reference`


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: IFNULL

am 14.02.2010 23:30:04 von dmagick

Ron Piggott wrote:
> How do I add " IFNULL " to the LEFT JOIN query? I either want the result
> from the database or a 0 instead of the word NULL
>
> Ron
>
> SELECT `store_product_profile`.`reference` , inventory.inventory,
> sold_1.quantity, sold_2.quantity, sold_3.quantity
> FROM `store_product_profile`
>
> LEFT JOIN (
>
> SELECT `store_product_inventory_control`.`store_product_profile_ref erence`
> , SUM( `store_product_inventory_control`.`quantity` ) AS inventory
> FROM `store_product_inventory_control`
> GROUP BY `store_product_inventory_control`.`store_product_profile_ref erence`
> ) AS inventory ON `store_product_profile`.`reference` =
> `inventory`.`store_product_profile_reference`

You don't add it to the join, it goes on a field you're selecting.

select IFNULL(inventory.inventory, 0) AS blah, ....

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php