【问题标题】:Delete all records from one table where they match criteria from two (or more) tables从一个表中删除与两个(或多个)表中的条件匹配的所有记录
【发布时间】:2014-09-19 11:00:05
【问题描述】:

考虑以下几点:

查询

SELECT * FROM 
`table1`,`table2` 
WHERE `table1`.`RemoteID` = `table2`.`ID` 
AND `table2`.`UserID`=1

如何将这些记录匹配的表 1 中的 SELECT 更改为 DELETE?它必须从 table1 中删除,而不是 table2

在不太具体的术语中,我想从 table1 中删除它们匹配两个表的某些条件的所有记录(离散和相对)

【问题讨论】:

  • 你可以使用子查询。

标签: mysql


【解决方案1】:

您可以将IN 与子查询一起使用

DELETE FROM table1
WHERE `table1`.`RemoteID` IN (
    SELECT ID 
    FROM table2
    WHERE `table2`.`UserID`=1)

【讨论】:

    【解决方案2】:

    试试这个,

    删除 来自table1 Id 在哪里 (选择table1.Id 来自table1 t1,table2 t2 其中 t1.RemoteID = t2.IDtable2.UserID = 1)

    【讨论】:

      猜你喜欢
      • 2010-12-27
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-04
      相关资源
      最近更新 更多