mysql - mysql删除查询出错

标签 mysql sql

delete from tx_table 
 where buyer_id in(select t.buyer_id     
                      from tx_table t                   
                      left join user_table u                  
                      on t.buyer_id=u.user_id                 
                      where u.user_id is null)

上述查询出现错误。错误是

sql error 1093:You can't specify target table 'tx_table' for update in FROM clause

请帮帮我

最佳答案

试试这个:

DELETE FROM tx_table 
WHERE buyer_id IN (
    SELECT buyer_id  FROM (
        SELECT DISTINCT  t.buyer_id AS buyer_id FROM tx_table 
        LEFT JOIN user_table u on t.buyer_id=u.user_id where u.user_id is null
    ) AS c
)

关于mysql - mysql删除查询出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29071812/

相关文章:

c# - 在 Windows Mobile 5 上将数据加载到 Sql CE 数据库的最快方法

java - Hibernate 查询 - 为什么它们如此奇怪?

sql - 如何将 Excel 序列日期数字转换为 Oracle SQL 中的日期

sql - PostgreSQL - 如何选择组函数的每一行?

mysql - 如何在 AFTER UPDATE 触发器中引用最近更新的行

mysql - SQL SELECT 并使数据中的某些列返回空白

php - php 中的可点击结果

mysql - 安装时更改mysql.sock路径(不在/tmp/下)

php - MySQL - 使用 OR 时如何知道哪个字段与结果匹配

php - 如何在 PDO 中按数字绑定(bind) ENUM 类型