【发布时间】:2016-05-13 03:32:15
【问题描述】:
一个简单的问题:
下面的更新查询在 SQL Server 中完美运行,但在 MySQL 中失败。
MySQL err.msg = "Error Code: 1093. You can't specify target table 'Pos' for update in FROM clause".
我可以找到几种解决方法,但正在寻找最佳实践。
update Pos set Printed = 1
where InvoiceNo = 3005
and Status = 'N'
and Pos.ItemNo IN
(select Pos.ItemNo from Pos,ItemMaster
where invoiceno = 3005
and status = 'N'
and printed = 0
and catType in ('B','L')
and Pos.itemno = ItemMaster.itemno)
【问题讨论】:
-
不是您的问题的答案,但您应该使用 ANSI-92 样式的连接语法……已经快 30 年了。 sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/…
-
是的;旧习难改。 . .
-
SQL Server 处理它,没问题,MySQL 不是这样。可能是错误的方法;我现在创建了一个效果最好的存储过程。 . .感谢您的链接。 . .
标签: mysql sql-server