Forum Moderators: coopster

Message Too Old, No Replies

Delete rows where " field" is empty

how to

         

henry0

12:56 pm on Aug 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello
how should look the syntax for the following:

I wish to del from a table all rows that show for example
email field empty

delete FROM whatever WHERE email = ' ';
will that be correct

thank you

regards

coopster

2:36 pm on Aug 22, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That will work. I usually don't leave a space in between the parentheses:
delete FROM whatever WHERE email = '';

Also, if the email column can contain NULL values, you may want to watch your operation carefully as it may not behave as you expect. From the MySQL Manual:

The concept of the NULL value is a common source of confusion for newcomers to SQL, who often think that NULL is the same thing as an empty string "". This is not the case! For example, the following statements are completely different:

mysql> INSERT INTO my_table (phone) VALUES (NULL);
mysql> INSERT INTO my_table (phone) VALUES ("");
.
.
.
To look for NULL values, you must use the IS NULL test. The following shows how to find the NULL phone number and the empty phone number:

mysql> SELECT * FROM my_table WHERE phone IS NULL;
mysql> SELECT * FROM my_table WHERE phone = "";

henry0

7:31 pm on Aug 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well Email as a Null default value
so in that case what will be the good tech

of course I may set a test table and play around
but I would rather be sure

thank you

coopster

7:59 pm on Aug 22, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



delete FROM whatever WHERE email = '' OR email IS NULL;

henry0

8:55 pm on Aug 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Coopster thanks