2 Replies - 18669 Views - Last Post: 30 December 2006 - 09:34 AM

#1 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

MySQL IF...ELSE

Posted 29 December 2006 - 11:57 PM

Hello, all.

I'm working on something for someone that involves changing the quantity of something. If the quantity is 1 or less, we are going to remove the row from the table. If it is 2 or more, we will just update the 'quantity' column, so that it has been decreased by 1. I thought I would shorten the process to 1 query, but this doesn't seem to work and I'm not having any luck with Google. Does anyone have any ideas?

IF SELECT * FROM cart WHERE quantity <= 1 AND owner = 1 AND item = 6
THEN
DELETE FROM cart WHERE owner = 1 AND item = 6;
ELSE
UPDATE cart SET quantity = quantity - 1 WHERE owner = 1 AND item = 6;
END IF



Thanks,
Girasquid

Is This A Good Question/Topic? 0
  • +

Replies To: MySQL IF...ELSE

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: MySQL IF...ELSE

Posted 30 December 2006 - 05:29 AM

I'm going to assume this is VB?
what code did you have working before?
Was This Post Helpful? 0
  • +
  • -

#3 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: MySQL IF...ELSE

Posted 30 December 2006 - 09:34 AM

View PostWilliam_Wilson, on 30 Dec, 2006 - 05:29 AM, said:

I'm going to assume this is VB?
what code did you have working before?

I'm using Perl, and the code that I had working was a few queries and a conditional. First, I'd select the value of quantity, and then based on whether it was greater than one or not, execute either the DELETE or UPDATE query.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1