使用相同的pcode和id更新两个表中的值 [英] update values from two table with the same pcode and id

查看:137
本文介绍了使用相同的pcode和id更新两个表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个名为tbl_sales和tbl_rsales的表.

I have 2 tables named tbl_sales and tbl_rsales.

让我们假设我对"tbl_sales"具有这些ff值

Lets assume that i have these ff value for "tbl_sales"

id | pcode | total |
2  | 12345 | 10    |
3  | 12345 | 10    |

让我们还假设我具有来自"tbl_rsales"的这些ff值

Lets assume also that i have these ff value from "tbl_rsales"

id | sales_id | total | pcode |
1  | 1        | 20    | 55555 |
2  | 2        | 10    | 12345 | 
3  | 3        | 10    | 12345 |

我可以轻松地从"tbl_sales"更新数据,但是我的问题是,当我从tbl_sales中通过"pcode"更新所有值时,"tbl_rsales"也必须进行更新.但只会更新tbl_rsales中"sales_id"中"tbl_sales"中的ID.换句话说. "tbl_rsales"中的sales_id 1不会仅更新sales_id 2,因为tbl_sales id和tbl_rsales"sales_id"是相同的,所以不会更新sales_id 2.对我来说这很复杂.任何想法都可以接受.

I can easily update data from "tbl_sales" but my problem is that when i update all value by "pcode" from tbl_sales "tbl_rsales" must be update also. but only those id's from "tbl_sales" that are in "sales_id" from tbl_rsales will update. so in other word. sales_id 1 from "tbl_rsales" will not update only sales_id 2 and 3 will be update because tbl_sales id and tbl_rsales "sales_id" is the same. it's lil complicated for me.any idea is accepted.

推荐答案

这是您要寻找的吗?

UPDATE TBL_SALES , TBL_RSALES
SET //WAHTEVER YOU WANT FROM THE TABLE
WHERE TBL_SALES,PCODE = TBL_RSALES.PCODE

这篇关于使用相同的pcode和id更新两个表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆