Solved

MySQL - I don't understand

Posted on 2014-12-11
2
201 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

770 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