...

View Full Version : Deleting an entire enry of data?



Democrazy
09-12-2011, 09:14 AM
I have this table:

+------+---------------+------------+
| id | primarycolour | pricerange |
+------+---------------+------------+
| 1 | black | 1 |
| NULL | brown | 2 |
+------+---------------+------------+

I want to delete the entire entry for NULL. I tried this, but it didn't work:

delete from testdb.products where id='NULL';

How can it be done?

Also, I don't think saying "deleting an entire entry of data" is correct. Is what I am asking to do is to delete a primary key?

djm0219
09-12-2011, 09:58 AM
You are deleting a row of data. What you tried will not work because it is comparing the string NULL to a NULL value which is different. If you id column is indeed a primary key column it should not be able to be null FWIW.


DELETE FROM `products` WHERE `id` = NULL

Democrazy
09-12-2011, 10:56 AM
I tried the code, but it didn't work.

http://i51.tinypic.com/kdwpzt.png

djm0219
09-12-2011, 11:48 AM
Sorry, syntax slightly off for a column that is null.


DELETE FROM `products` WHERE `id` IS NULL

Democrazy
09-12-2011, 12:30 PM
It worked!!!! :D

Thank you. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum