Solved

MySQL - I don't understand

Posted on 2014-12-11
2
195 Views
Last Modified: 2014-12-11
See attached. This is a small sample of a table (named "customer") that I have.

Notice the column called cutype in most cases the value is NULL (in italics), I don't know what that means.

I run this query: DELETE from customer where cutype <> 'i'

It deletes the 79 rows that have blank (not NULL) in the column.

It leaves all the rest.

Actually, at this moment, there are NO rows in the table where cutype = 'i'.

Why does it leave the NULL ones? That is not a value of 'i'.

Thanks
cutype.jpg
0
Comment
Question by:Richard Korts
2 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 40495213
Null isn't really an empty value so much as it is the absense of any value. The way to check for null is by using IS NULL. For example, to delete rows where cutype is null, you'd have to do this:

DELETE FROM customer WHERE cutype IS NULL;

if you want to get rid of anything that is either null or NOT i, do this:

DELETE FROM customer WHERE cutype IS NULL OR cutype <> 'i';
0
 
LVL 58

Expert Comment

by:Gary
ID: 40495214
NULL values are a bit special
http://dev.mysql.com/doc/refman/5.1/en/working-with-null.html

If you want to delete rows with NULL values you have to declare them

    DELETE from customer where cutype <> 'i' OR cutype IS NULL
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Creating and Managing Databases with phpMyAdmin in cPanel.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now