Skip to main content
added 6 characters in body
Source Link
Smeagel
  • 5
  • 1
  • 3

I'm trying to update 2 rows at once, I want to:

  1. Set coupon.start (datetime) to the original account.vipExpires (datetime)

  2. Add coupon.days (int) to account.vipExpires (datetime)

  3. Set coupon.end (datetime) to the new value of account.vipExpires after coupon.days have been added

    UPDATE accounts a, coupons c SET c.start = a.vipExpires, a.vipExpires = DATE_ADD(a.vipExpires, INTERVAL c.days DAY), c.end = a.vipExpires WHERE a.id = 1 AND c.id = 1;

The result I'm getting is:

c.start, a.vipExpires, c.end ALL end up as the new datetime with the added days.

How do I make c.start be equal to the original a.vipExpires value?

I originally thought the SET operations would execute in the order specified, it seems I was wrong.

I'm trying to update 2 rows at once, I want to:

  1. Set coupon.start (datetime) to the original account.vipExpires (datetime)

  2. Add coupon.days (int) to account.vipExpires (datetime)

  3. Set coupon.end (datetime) to the new value of account.vipExpires after coupon.days have been added

    UPDATE accounts a, coupons c SET c.start = a.vipExpires, a.vipExpires = DATE_ADD(a.vipExpires, INTERVAL c.days DAY), c.end = a.vipExpires WHERE a.id = 1 AND c.id = 1;

The result I'm getting is:

c.start, a.vipExpires, c.end ALL end up as the new datetime with the added days.

How do I make c.start be equal to the original a.vipExpires value?

I originally thought the SET operations would execute in the order specified, it seems I was wrong.

I'm trying to update 2 rows at once, I want to:

  1. Set coupon.start (datetime) to the original account.vipExpires (datetime)

  2. Add coupon.days (int) to account.vipExpires (datetime)

  3. Set coupon.end (datetime) to the new value of account.vipExpires after coupon.days have been added

    UPDATE accounts a, coupons c SET c.start = a.vipExpires, a.vipExpires = DATE_ADD(a.vipExpires, INTERVAL c.days DAY), c.end = a.vipExpires WHERE a.id = 1 AND c.id = 1;

The result I'm getting is:

c.start, a.vipExpires, c.end ALL end up as the new datetime with the added days.

How do I make c.start be equal to the original a.vipExpires value?

I originally thought the SET operations would execute in the order specified, it seems I was wrong.

Source Link
Smeagel
  • 5
  • 1
  • 3

UPDATE SET values ignoring set ordering

I'm trying to update 2 rows at once, I want to:

  1. Set coupon.start (datetime) to the original account.vipExpires (datetime)

  2. Add coupon.days (int) to account.vipExpires (datetime)

  3. Set coupon.end (datetime) to the new value of account.vipExpires after coupon.days have been added

    UPDATE accounts a, coupons c SET c.start = a.vipExpires, a.vipExpires = DATE_ADD(a.vipExpires, INTERVAL c.days DAY), c.end = a.vipExpires WHERE a.id = 1 AND c.id = 1;

The result I'm getting is:

c.start, a.vipExpires, c.end ALL end up as the new datetime with the added days.

How do I make c.start be equal to the original a.vipExpires value?

I originally thought the SET operations would execute in the order specified, it seems I was wrong.