Re: Little Info...

From: Date: Wed, 29 Feb 2012 18:27:45 +0000
Subject: Re: Little Info...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-316807@lists.php.net to get a copy of this message
On Wed, Feb 29, 2012 at 7:01 PM, Don Wieland <donw@pointmade.net> wrote: > This is a bit related to PHP but mostly mySQL (is there a similar list for > this stuff? Let me know please) > > In my mySQL query editor, I am trying to return a value of 0 when there is > no related rows from this query: > > (select if(count(ip.payment_amount) IS NOT NULL, count(ip.payment_amount) , > 0)  FROM tl_trans_pmt_items ip WHERE t.transaction_id = ip.inv_id GROUP BY > ip.inv_id) as d, > > regardless of the combination I use, invalid relationships come back as NULL > - need to return 0  so I can use it in a math formula. > > Probably simple - maybe ;-) > > Thanks, > > Don While Daniel is right, you can use COALESCE for this. eg. select COALESCE(count(ip.payment_amount), 0) - Matijn

« previous php.general (#316807) next »