> Is it possible to update a field with the result of a select. > For example:
Try: SELECT @newbalance := ordr_order.total_cost - sum(ordr_payment.amount) FROM ordr_order LEFT JOIN ordr_payment on ordr_payment.ordr_order_id = ordr_order.id WHERE ordr_order.id = 1; UPDATE ordr_order SET balance = @newbalance WHERE id = 1; > UPDATE ordr_order SET balance = ('SELECT ordr_order.total_cost - > sum(ordr_payment.amount) FROM ordr_order LEFT JOIN ordr_payment on > ordr_payment.ordr_order_id = ordr_order.id WHERE ordr_order.id = 1') > WHERE id = 1 This doesn't work because it's setting balance to the text of the query, not the result of the query itself. Since balance is probably not a string type, it gets converted to a number which probably ends up making it zero. If MySQL supported subselects it might work except without the single quotes around the query. --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php