i want to update a table column by taking i/p from two tables in a single query.
This is what i have tried.
$query="UPDATE all_stores a
inner join i_v i on
a.id = i.child_id
set a.qty = (a.qty-i.qty)";
But this is not updating the table.
Where Table-all_stores is:
id- name qty - dec_qty
1 a1 68 0
2 b2 32 0
3 c3 12 0
4 d4 43 0
And table-i_v is:
id- name qty - child_id
1 a1 12 1
2 a2 32 2
3 a1 11 1
4 a1 23 1
if I understand correctly, you want to do this:
UPDATE all_stores a
set a.qty = (a.qty-(select sum(qty) from i_v i where a.id = i.id))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.