[英]How Can I Query for Unique Value and Update another Field in Same Table If return True mysql php
[英]Mysql query to update row and return the new value with the same query
我有這個簡單的查詢,可以更新產品數量:
$updprqty='UPDATE products set
available_qty = available_qty - '.$qty.'
WHERE id = '.$pid.'';
我還應該添加什么,以便獲得available_qty的新值? 謝謝
您也可以檢查此鏈接,也許您會對此有所了解
$updprqty='UPDATE products set
available_qty = (select available_qty from products where id = ' .$pid . ') - '.$qty.'
WHERE id = '.$pid.'';
別名介紹
$updprqty='update products set available_qty = x.available_qty from (select available_qty, id from products) - '.$qty.' where id = ' .$pid . ') as x where id = x.id';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.