【问题标题】:Updating column1 in table1 only if matched column3 in table2仅当与 table2 中的 column3 匹配时才更新 table1 中的 column1
【发布时间】:2014-02-12 06:47:41
【问题描述】:

只有当 table1 中的 column2 与 table2 中的 column3 匹配时,我才想更新 table1 中的 column1。

我正在尝试使用此查询,但我收到一条错误消息,提示我缺少等号。

谁能帮忙?

update schema1.table1 
set schema1.table1.column1
where schema1.table1.column2 = table2.column1

【问题讨论】:

    标签: oracle


    【解决方案1】:

    你的错误说明了一切。您没有为该列分配任何值。尝试使用相等的= 符号设置值

    你可以试试这个:

    update schema1.table1 
    set schema1.table1.column1 = //The value which you want to store
    where schema1.table1.column2 = table2.column1
    

    【讨论】:

      【解决方案2】:

      试试这个查询:

      update schema1.table1 t1 
      set t1.column1 = (select t2.columnX from table2 t2
                        where t1.column2 = t2.column1)
      where t1.column2 in (select column1 from table2)
      

      【讨论】:

        【解决方案3】:

        如错误消息中所示,您错过了 = 并且未在查询中为 schema1.table1.column1 分配任何值。

        试试这样:

        UPDATE schema1.table1 
        SET    schema1.table1.column1 = <your_value>
        WHERE  schema1.table1.column2 = table2.column1;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-12-07
          • 2022-01-28
          • 2019-09-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多