【问题标题】:SQL How do I update a Column in a table, from a column from another table, only if the data in another column has the same value as another columnSQL如何从另一个表中的列更新表中的列,仅当另一列中的数据与另一列具有相同的值时
【发布时间】:2021-08-31 10:55:03
【问题描述】:

你好,这是我的问题,

SQL 如何从另一个表中的列更新表中的列,前提是另一列中的数据与另一列具有相同的值。

在 SQL 中:

表 1:

Part NO Description Notes
A30134 Straight Part Eq Used for Equipment
AS3043 3/4 Hedge Used for Temp
AS3021 1/3 Hedge Used for In House
AS3011 1/4 Sprocket Used for House

表 2:

Part NO Description
A30134 Hatchet
AS3021 1/8 Hedge

结果表:

Part NO Description Notes
A30134 Hatchet Used for Equipment
AS3043 3/4 Hedge Used for Temp
AS3021 1/8 Hedge Used for In House
AS3011 1/4 Sprocket Used for House

所以基本上,只需从表 2 中获取 2 列,并将部件号与表 1 的部件号进行比较,并且仅根据表 2 中的描述更新表 1 中的描述,而不更改任何其他描述或部件号。

【问题讨论】:

  • 用您正在使用的数据库标记您的问题。
  • 我做错了。

标签: sql database ms-access


【解决方案1】:

你可以试试updatejoin

update table1 inner join
       table2
       on table1.part_no = table2.partno
    set table1.description = table2.description;

【讨论】:

    猜你喜欢
    • 2011-04-18
    • 2022-01-23
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    • 2019-07-25
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多