简体   繁体   English

MySQL:根据条件删除行,并带有来自另一个表的数据,并且不进行联接

[英]MySQL: deleting rows based on a condition with data from another table and NO JOIN

I have a TABLE1 like this: 我有一个这样的TABLE1:

在此处输入图片说明

And a TABLE2 like this: 和这样的TABLE2:

在此处输入图片说明

I want to delete entries from table 1 whose endTimestamp is not equal to ANY table 2 entry endTimestamp, with a margin of 1000 time units. 我想从表1中删除其endTimestamp不等于任何表2项endTimestamp的条目,并以1000个时间单位为裕量。

(I know in this example all the entries from table 1 and table 2 have the same timestamp values, so the 5 entries from table 1 should be kept, and any other should be erased if existed) (我知道在此示例中,表1和表2中的所有条目都具有相同的时间戳记值,因此应保留表1中的5个条目,如果存在,则应删除任何其他条目)

Since the ids of both tables are not related to each other, I can't perform a JOIN operation as long as I know. 由于两个表的ID都不相互关联,因此只要我知道,就无法执行JOIN操作。

How can I do this? 我怎样才能做到这一点?

EDIT: Tried here . 编辑: 在这里尝试 Works, but does not work at my server :| 有效,但是在我的服务器上不起作用:|

You're looking for : 您正在寻找 :

delete from table1 where endTimestamp not in (Select endTimestamp from table2)

Edit : As pointed out by @user2864740, you can very well use Join here too, even if the ids of both tables are not related to each other. 编辑:正如@ user2864740所指出的,即使两个表的ID彼此都不相关,您也可以很好地在这里使用Join。

DELETE FROM table1 INNER JOIN table2 ON table1.endTimestamp = table2.endTimestamp;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM