Professional Web Applications Themes

A MySQL question - PHP Development

Ok, I want to delete only 1 row off of a database table... Example: I have a table with columns "user" and "item"... Lets say the table contains the following rows (user | item): 582-668243 | Toothbrush 582-668243 | Toothbrush 582-668243 | Toothbrush 582-668243 | Trash can 582-668243 | Trash can 582-668243 | Something else 582-668243 | Something else 582-668243 | Something else 582-668243 | Something else 720-387690 | Dog treats 720-387690 | Car 720-387690 | Car 720-387690 | Toothbrush 720-387690 | Toothbrush Ok, user 582-668243 is buying a lot, eh? LoL Anyway, how can I remove only 1 Toothbrush ...

  1. #1

    Default A MySQL question

    Ok, I want to delete only 1 row off of a database table...
    Example:
    I have a table with columns "user" and "item"...
    Lets say the table contains the following rows (user | item):
    582-668243 | Toothbrush
    582-668243 | Toothbrush
    582-668243 | Toothbrush
    582-668243 | Trash can
    582-668243 | Trash can
    582-668243 | Something else
    582-668243 | Something else
    582-668243 | Something else
    582-668243 | Something else
    720-387690 | Dog treats
    720-387690 | Car
    720-387690 | Car
    720-387690 | Toothbrush
    720-387690 | Toothbrush

    Ok, user 582-668243 is buying a lot, eh? LoL
    Anyway, how can I remove only 1 Toothbrush from user 582-668243?
    I just want the query... I've been trying to find it out for a few hours
    now...

    Thanks in advance!

    --

    - Zavaboy
    [email]zavaboyhotmail.com[/email]
    [url]www.zavaboy.com[/url]


    Zavaboy Guest

  2. #2

    Default Re: A MySQL question


    "Zavaboy" <zavaboyhotmail.com> wrote in message
    news:20030714211313.86984.qmailpb1.pair.com...
    > Ok, I want to delete only 1 row off of a database table...
    > Example:
    > I have a table with columns "user" and "item"...
    > Lets say the table contains the following rows (user | item):
    > 582-668243 | Toothbrush
    > 582-668243 | Toothbrush
    > 582-668243 | Toothbrush
    > 582-668243 | Trash can
    > 582-668243 | Trash can
    > 582-668243 | Something else
    > 582-668243 | Something else
    > 582-668243 | Something else
    > 582-668243 | Something else
    > 720-387690 | Dog treats
    > 720-387690 | Car
    > 720-387690 | Car
    > 720-387690 | Toothbrush
    > 720-387690 | Toothbrush
    >
    > Ok, user 582-668243 is buying a lot, eh? LoL
    > Anyway, how can I remove only 1 Toothbrush from user 582-668243?
    > I just want the query... I've been trying to find it out for a few hours
    > now...
    >
    > Thanks in advance!
    >
    > --
    >
    > - Zavaboy
    > [email]zavaboyhotmail.com[/email]
    > [url]www.zavaboy.com[/url]

    You can try putting "LIMIT 1" on the end of your query but to be honest I
    don't know if LIMIT works with the DELETE command. Worth a try. Ideally
    you should have an additional column with an autoincrementing value to act
    as your primary key and you delete on that key.

    - Kevin


    Kevin Stone Guest

  3. #3

    Default Re: [PHP] A MySQL question

    --- zavaboy <zavaboyhotmail.com> wrote:
    > Lets say the table contains the following rows (user | item):
    > 582-668243 | Toothbrush
    > 582-668243 | Toothbrush
    > 582-668243 | Toothbrush
    ....
    > Anyway, how can I remove only 1 Toothbrush from user 582-668243?
    With the information you provided, you can't. You should never have multiple
    rows in the database that are non-unique, and this is one reason why. You need
    a primary key.
    > I just want the query
    You should rather spend your time learning some database fundamentals rather
    than asking this list (not a database list, in fact) for spoon-fed answers. You
    will appreciate the knowledge more than the answer.

    Chris

    =====
    Become a better Web developer with the HTTP Developer's Handbook
    [url]http://httphandbook.org/[/url]
    Chris Shiflett Guest

  4. #4

    Default Re: [PHP] A MySQL question

    zavaboy <zavaboyhotmail.com> wrote:
    > Ok, I want to delete only 1 row off of a database table...
    > Example:
    > I have a table with columns "user" and "item"...
    > Lets say the table contains the following rows (user | item):
    > 582-668243 | Toothbrush
    > 582-668243 | Toothbrush
    Note the 'LIMIT' part in the delete statment.
    [url]http://www.mysql.com/doc/en/DELETE.html[/url]
    > [...]
    >
    > Thanks in advance!
    >
    > --
    >
    > - Zavaboy
    > [email]zavaboyhotmail.com[/email]
    > [url]www.zavaboy.com[/url]
    >
    HTH
    Curt
    --

    Curt Zirzow Guest

  5. #5

    Default Re: [PHP] A MySQL question

    Ok, I added a primary key. I figured it out and I have it working... Thanks!

    "Chris Shiflett" <shiflettphp.net> wrote in message
    news:20030714212006.75107.qmailweb14308.mail.yaho o.com...
    > --- zavaboy <zavaboyhotmail.com> wrote:
    > > Lets say the table contains the following rows (user | item):
    > > 582-668243 | Toothbrush
    > > 582-668243 | Toothbrush
    > > 582-668243 | Toothbrush
    > ...
    > > Anyway, how can I remove only 1 Toothbrush from user 582-668243?
    >
    > With the information you provided, you can't. You should never have
    multiple
    > rows in the database that are non-unique, and this is one reason why. You
    need
    > a primary key.
    >
    > > I just want the query
    >
    > You should rather spend your time learning some database fundamentals
    rather
    > than asking this list (not a database list, in fact) for spoon-fed
    answers. You
    > will appreciate the knowledge more than the answer.
    >
    > Chris
    >
    > =====
    > Become a better Web developer with the HTTP Developer's Handbook
    > [url]http://httphandbook.org/[/url]

    Zavaboy Guest

  6. #6

    Default RE: [PHP] A MySQL question

    You have made a mistake in your database design. Every table should have a
    primary key that allows you to uniquely identify any single row in the
    table. You do not have a primary key, hence when you want to delete a
    single row from a series of duplicates, you can't do it. Unlike oracle,
    mysql has no rowid.

    -----Original Message-----
    From: zavaboy [mailto:zavaboyhotmail.com]
    Sent: Monday, July 14, 2003 2:13 PM
    To: [email]php-generallists.php.net[/email]
    Subject: [PHP] A MySQL question

    Ok, I want to delete only 1 row off of a database table...
    Example:
    I have a table with columns "user" and "item"...
    Lets say the table contains the following rows (user | item):
    582-668243 | Toothbrush
    582-668243 | Toothbrush
    582-668243 | Toothbrush
    582-668243 | Trash can
    582-668243 | Trash can
    582-668243 | Something else
    582-668243 | Something else
    582-668243 | Something else
    582-668243 | Something else
    720-387690 | Dog treats
    720-387690 | Car
    720-387690 | Car
    720-387690 | Toothbrush
    720-387690 | Toothbrush

    Ok, user 582-668243 is buying a lot, eh? LoL
    Anyway, how can I remove only 1 Toothbrush from user 582-668243?
    I just want the query... I've been trying to find it out for a few hours
    now...

    Thanks in advance!

    --

    - Zavaboy
    zavaboyhotmail.com
    www.zavaboy.com



    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php


    Giz Guest

Similar Threads

  1. php or mysql question
    By Jason Cooke in forum PHP Development
    Replies: 2
    Last Post: January 20th, 07:25 PM
  2. dbi::mysql question
    By rob merritt in forum PERL Beginners
    Replies: 0
    Last Post: January 2nd, 06:53 PM
  3. More of a mysql question
    By hokieghal99 in forum PHP Development
    Replies: 1
    Last Post: October 27th, 02:43 PM
  4. Question regarding PHP and mySQL
    By Me@lost_pls_help in forum PHP Development
    Replies: 1
    Last Post: July 27th, 09:57 PM
  5. PHP + MYSQL Question!
    By R.Lange in forum PHP Development
    Replies: 2
    Last Post: July 20th, 01:03 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139