[英]update sql table from two tables Using a single query
i want to update a table column by taking i/p from two tables in a single query.我想通过在单个查询中从两个表中获取 i/p 来更新表列。
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:其中 Table-all_stores 是:
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:表 i_v 是:
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.