MySQL Update a field value with subquery with multiple returning rows?

It's probably worthwhile to ensure that your UPDATE statement is trying to update each user's row exactly once. A subquery is the best way to do this, most efficiently implemented as a joined table.

It's probably worthwhile to ensure that your UPDATE statement is trying to update each user's row exactly once. A subquery is the best way to do this, most efficiently implemented as a joined table: UPDATE bank JOIN (SELECT LOWER(bonds. Holder) as user, SUM(bonds.

IssuePrice * bonds. Coupon) as total FROM bonds WHERE LOWER(bonds. Holder)!

= 'bank' GROUP BY user ) as increments ON increments. User = LOWER(bank. User) SET bank.

Cash = ROUND(bank. Cash + increments. Total, 2), bank.

Earned = ROUND(bank. Earned + increments. Total, 2) (For more optimization, the LOWER and ROUND calls should probably be eliminated, but that's another discussion.).

Thanks, this worked! – Gilles Lesire Dec 11 '10 at 12:17.

The most straighforward way is to use sub-selects and update the fields individually... UPDATE bank ba1 SET ba1. Cash = ba1. Cash + (ROUND(SELECT SUM(bo.

IssuePrice * bo. Coupon) FROM bank ba2 JOIN bonds bo ON bo. User = ba2.

User WHERE ba2. User = ba1. User), 2) ...

This worked too but I think the other query is easier and more performant. – Gilles Lesire Dec 11 '10 at 12:19.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send