?
Solved

MySQL - I don't understand

Posted on 2014-12-11
2
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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