Bluehost.com Web Hosting $6.95

A MySQL question

This is a discussion on A MySQL question within the PHP General forums, part of the PHP Programming Forums category; Ok, I want to delete only 1 row off of a database table... Example: I have a table with columns &...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-14-2003
Zavaboy
 
Posts: n/a
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
zavaboy@hotmail.com
www.zavaboy.com


Reply With Quote
  #2 (permalink)  
Old 07-14-2003
Kevin Stone
 
Posts: n/a
Default Re: A MySQL question


"Zavaboy" <zavaboy@hotmail.com> wrote in message
news:20030714211313.86984.qmail@pb1.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
> zavaboy@hotmail.com
> www.zavaboy.com



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


Reply With Quote
  #3 (permalink)  
Old 07-14-2003
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] A MySQL question

--- zavaboy <zavaboy@hotmail.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
http://httphandbook.org/
Reply With Quote
  #4 (permalink)  
Old 07-14-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] A MySQL question

zavaboy <zavaboy@hotmail.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.
http://www.mysql.com/doc/en/DELETE.html

> [...]
>
> Thanks in advance!
>
> --
>
> - Zavaboy
> zavaboy@hotmail.com
> www.zavaboy.com
>


HTH
Curt
--

Reply With Quote
  #5 (permalink)  
Old 07-15-2003
Zavaboy
 
Posts: n/a
Default Re: [PHP] A MySQL question

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

"Chris Shiflett" <shiflett@php.net> wrote in message
news:20030714212006.75107.qmail@web14308.mail.yaho o.com...
> --- zavaboy <zavaboy@hotmail.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
> http://httphandbook.org/



Reply With Quote
  #6 (permalink)  
Old 07-15-2003
Giz
 
Posts: n/a
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:zavaboy@hotmail.com]
Sent: Monday, July 14, 2003 2:13 PM
To: php-general@lists.php.net
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
zavaboy@hotmail.com
www.zavaboy.com



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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0