简体   繁体   English

更新 - SELECT - MYSQL #1093 - 您不能在 FROM 子句中指定目标表“temp1”进行更新

[英]UPDATE - SELECT - MYSQL #1093 - You can't specify target table 'temp1' for update in FROM clause

I can't find solution to correct this big query, I always receive an error from database.我找不到解决这个大查询的解决方案,我总是收到来自数据库的错误。

I have tre tables and I need to make changes on some attribute on some condition:我有 tre 表,我需要在某些条件下对某些属性进行更改:

UPDATE o36t_orders as temp1,
  mytable as temp2
SET
  temp1.bonifico = 1,
  temp2.ultimo = 1
WHERE
  temp1.id_order IN (
    SELECT
      id_order
    FROM o36t_orders
    LEFT JOIN o36t_address ON (o36t_address.id_address = o36t_orders.id_address_delivery)
    LEFT JOIN mytable ON (
        mytable.Causale = CONCAT(
          o36t_address.lastname,
          ' ',
          o36t_address.firstname
        )
      )
    WHERE
      o36t_orders.bonifico <> 1
  )
  AND temp2.id IN (
    SELECT
      id
    FROM o36t_orders
    LEFT JOIN o36t_address ON (o36t_address.id_address = o36t_orders.id_address_delivery)
    LEFT JOIN mytable ON (
        mytable.Causale = CONCAT(
          o36t_address.lastname,
          ' ',
          o36t_address.firstname
        )
      )
    WHERE
      o36t_orders.bonifico <> 1
  ) 

Since the subqueries of the 2 IN clauses are identical (except the retuned column), I think that you can do what you want by a straight inner join of the 2 tables and that subquery (returning both columns):由于 2 IN 子句的子查询是相同的(除了重新调整的列),我认为您可以通过 2 个表和该子查询的直接内部连接(返回两列)来做您想做的事情:

UPDATE o36t_orders temp1
INNER JOIN (
    SELECT
      id, id_order
    FROM o36t_orders
    LEFT JOIN o36t_address ON (o36t_address.id_address = o36t_orders.id_address_delivery)
    LEFT JOIN mytable ON (
        mytable.Causale = CONCAT(
          o36t_address.lastname,
          ' ',
          o36t_address.firstname
        )
      )
    WHERE
      o36t_orders.bonifico <> 1
) t ON t.id_order = temp1.id_order
INNER JOIN mytable temp2 ON temp2.id = t.id
SET
  temp1.bonifico = 1,
  temp2.ultimo = 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL#1093 - 您无法在FROM子句中为更新指定目标表&#39;giveaways&#39; - MySQL #1093 - You can't specify target table 'giveaways' for update in FROM clause MySQL问题“错误代码:1093。您无法在FROM子句中指定目标表&#39;product&#39;进行更新” - MySQL issue “Error Code: 1093. You can't specify target table 'product' for update in FROM clause” mysql错误代码1093:您不能在FROM子句中指定目标表进行更新 - mysql error code 1093: You can't specify target table for update in FROM clause mysql错误代码:1093。您不能在FROM子句中指定目标表“ S”进行更新 - mysql Error Code: 1093. You can't specify target table 'S' for update in FROM clause MySQL 5.7 错误(1093:您无法在 FROM 子句中为更新指定目标表 ___)-通常的解决方案不起作用 - MySQL 5.7 error (1093: You can't specify target table ___ for update in FROM clause) - usual solution not working 如何解决此 mysql 错误 #1093 - 您无法在 FROM 子句中指定目标表 'person' 进行更新 - How to resolve this mysql error #1093 - You can't specify target table 'person' for update in FROM clause MySql 错误代码:1093-您不能在 FROM 子句中指定目标表“n1”进行更新 - MySql Error code: 1093- You can't specify target table 'n1' for update in FROM clause 获取MySQL错误代码1093:UPDATE中的“您无法在FROM子句中指定目标表&#39;fdd1&#39;进行更新” - Getting a MySQL error code 1093: “You can't specify target table 'fdd1' for update in FROM clause” in UPDATE 错误代码:1093。您无法在FROM子句中指定目标表“ t”进行更新 - Error Code: 1093. You can't specify target table 't' for update in FROM clause 错误代码:1093。您无法在FROM子句中指定目标表“表”进行更新 - Error Code: 1093. You can't specify target table 'table' for update in FROM clause
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM