----- Original Message -----
From: "Scott Haneda"
> on 5/5/05 2:11 AM, Joerg Bruehe at [EMAIL PROTECTED] wrote:
> Basically, I have a chopping cart, this one is a little weird, for reasons
> not worth explaining, you have a cart when a user is not logged in, and
they
> *may* have one they made at some point when logged in.  There is a chance
> the logged in cart already has stuff in the non logged in cart, I don't
want
> duplicate items in the cart, so I want to just get rid of the oldest one.

I'd add a UNIQUE index on user id and product id (beware of the handling of
NULL values!) and use REPLACE to add the new data.
"REPLACE works exactly like INSERT, except that if an old record in the
table has the same value as a new record for a PRIMARY KEY or a UNIQUE
index, the old record is deleted before the new record is inserted."
http://dev.mysql.com/doc/mysql/en/replace.html

Regards, Jigal.


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to