LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-12-2007, 04:18 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
SQL question - checking for NULL?


In my table, I have a blob field called "order_comments" The following query produces the following output:

Code:
select orders_supplement_id, shipping, order_comments from orders_supplement, orders where orders_supplement_id > 110000 AND order_id = orders_supplement_id AND shipping not like "%US%" limit 10;
+----------------------+----------------+-----------------------+
| orders_supplement_id | shipping       | order_comments        |
+----------------------+----------------+-----------------------+
|               110007 | Express-Canada | NULL                  | 
|               110050 | Canada         | You have nice things! | 
|               110055 | Intl           | NULL                  | 
|               110081 | Canada         | NULL                  | 
|               110082 | Canada         | NULL                  | 
|               110101 | Canada         | NULL                  | 
|               110107 | Canada         | NULL                  | 
|               110119 | Intl           | NULL                  | 
|               110126 | Canada         | NULL                  | 
|               110147 | Canada         | NULL                  | 
+----------------------+----------------+-----------------------+
10 rows in set (0.00 sec)
So now, I want to pick only those results that have something in the comment field, but I can't seem to get it to work. I've tried:

order_comments is not null
order_comments not like "NULL%"

... and a few other ridiculous incarnations, but I can't seem to get anything other than the results above. ideas?
 
Old 04-13-2007, 08:13 AM   #2
zaichik
Member
 
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
Hello Brian,

IS NOT NULL ought to do it. Strange.
Code:
mysql> describe test;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| pk       | int(11) |      |     | 0       |       |
| my_field | blob    | YES  |     | NULL    |       |
+----------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> select * from test;
+----+----------+
| pk | my_field |
+----+----------+
|  1 | NULL     |
|  2 | hi       |
+----+----------+
2 rows in set (0.00 sec)

mysql> select * from test where my_field is not NULL;
+----+----------+
| pk | my_field |
+----+----------+
|  2 | hi       |
+----+----------+
1 row in set (0.00 sec)

mysql>
Are you getting an error message? Is the problem perhaps elsewhere in the query? NULL is a special value and a reserved keyword in standard SQL, so you do not want to put quotes around it (or you will end up matching the string 'NULL', which is a different beast altogether, of course).

If you could post the entire query along with the results, as well as which RDBMS you are using, that might help.

Last edited by zaichik; 04-13-2007 at 10:23 AM.
 
Old 04-13-2007, 10:11 AM   #3
haydari
LQ Newbie
 
Registered: Apr 2007
Posts: 13

Rep: Reputation: 0
And also null is not equal to null so you can't compare or check them in this way. As mentioned is NULL and is not NULL have to be the proper command.

Last edited by haydari; 04-13-2007 at 10:12 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Null modem cable question msills Linux - Hardware 1 11-09-2005 06:15 PM
fstab-sync: error: libhal_ctx_init_direct: (null): (null) rpz Linux - Hardware 1 11-01-2005 05:42 AM
checking for null values from config file? zerointeger Programming 1 10-12-2005 11:29 AM
checking pointer is non-null causes segmentation fault in c++ markhod Programming 10 01-11-2005 11:28 AM
Question about null modem cable Luke727 Linux - Hardware 5 05-29-2004 07:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration