Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Deleting an entire enry of data?

    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:
    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?

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    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

  • #3
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    I tried the code, but it didn't work.

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

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    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

  • Users who have thanked djm0219 for this post:

    Democrazy (09-12-2011)

  • #5
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    It worked!!!!

    Thank you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •