Re: NULL values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 3, 2010 at 6:25 PM, Ron Piggott
<ron.piggott@xxxxxxxxxxxxxxxxxx> wrote:
>
> When I do the following query in mySQL only 1 record is retrieved.
>
> SELECT * FROM `paypal_payment_info` WHERE `os1` NOT LIKE 'commission_paid'
>
> I am surprised by this.  This one record has no characters in it, but the “INSERT INTO” that created it used: ( `os1` ) VALUES ( ‘’ ) instead of: ( `os1` ) VALUES ( NULL ) .  There are a number of records where `os1` is NULL.  I would like these rows to retrieve as well.  How do I make a WHERE clause for a cell that is NULL ?
>

You need to explicitly check for NULLs.  The regular operators (<, >,
=, LIKE) work on values.  NULL columns have no value, so you need to
use IS NULL or IS NOT NULL.  Also, if you're not doing wildcard
matches, you should probably just use <> or =:

SELECT * FROM `paypal_payment_info` WHERE (`os1` <> 'commission_paid'
OR `os` IS NULL)

  Scotty

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




[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux