【问题标题】:SQL subquery error giving can't specify against targetSQL 子查询错误给定不能针对目标指定
【发布时间】:2022-10-14 05:56:34
【问题描述】:
update customers 
set transaction_id = ( 
    select transaction_id from transactions
    where transaction_type IN (select transaction_type from customers where id = 1)
);

给出错误 1093。您不能在 where 子句中指定要更新的目标表?任何人都知道为什么我不允许使用这个子查询?

【问题讨论】:

    标签: sql plsql subquery


    【解决方案1】:

    错误 1093 来自 mysql,所以我认为您错误标记了它。

    但基本上您需要创建一个子查询,因此数据库不使用您正在尝试更改的客户。

    您必须确保子查询仅返回一个标量值

    CREATE tABLe customers (id int , transaction_id int)
    
    CREATE tABLE transactions (transaction_id int,transaction_type int) 
    
    update customers 
    set transaction_id = ( 
        select transaction_id from transactions
        where transaction_type IN (select transaction_type from (SELECT transaction_type  FROM customers where id = 10) c )
    );
    
    
    Rows matched: 0  Changed: 0  Warnings: 0
    

    fiddle

    【讨论】:

      猜你喜欢
      • 2021-08-15
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      • 2019-11-16
      • 2011-07-26
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多