Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-12-2011, 09:14 AM   PM User | #1
Democrazy
Banned

 
Join Date: Sep 2011
Posts: 140
Thanks: 17
Thanked 0 Times in 0 Posts
Democrazy has a little shameless behaviour in the past
Deleting an entire enry of data?

I have this table:
Quote:
+------+---------------+------------+
| 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:
Code:
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?
Democrazy is offline   Reply With Quote
Old 09-12-2011, 09:58 AM   PM User | #2
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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.

Code:
DELETE FROM `products` WHERE `id` = NULL
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Old 09-12-2011, 10:56 AM   PM User | #3
Democrazy
Banned

 
Join Date: Sep 2011
Posts: 140
Thanks: 17
Thanked 0 Times in 0 Posts
Democrazy has a little shameless behaviour in the past
I tried the code, but it didn't work.

http://i51.tinypic.com/kdwpzt.png
Democrazy is offline   Reply With Quote
Old 09-12-2011, 11:48 AM   PM User | #4
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
Sorry, syntax slightly off for a column that is null.

Code:
DELETE FROM `products` WHERE `id` IS NULL
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Users who have thanked djm0219 for this post:
Democrazy (09-12-2011)
Old 09-12-2011, 12:30 PM   PM User | #5
Democrazy
Banned

 
Join Date: Sep 2011
Posts: 140
Thanks: 17
Thanked 0 Times in 0 Posts
Democrazy has a little shameless behaviour in the past
It worked!!!!

Thank you.
Democrazy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:28 AM.


Advertisement
Log in to turn off these ads.