查找另一个表后从一个表中删除 - SQL

发布于 2024-11-08 06:00:09 字数 262 浏览 0 评论 0原文


我有两个表

Invited

  • UID [pk]

Active

  • UID [pk]

我想从 Active 中存在的 Invited 中删除 UID
我可以通过加入来做到这一点还是唯一的方法是使用 NOT IN 或 IN

Hiii
I have two tables

Invited

  • UID [pk]

Active

  • UID [pk]

I want to delete UID from Invited who is present in Active table
Can i do this with Joining or the only approach is to use NOT IN or IN ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷弦 2024-11-15 06:00:09

是的,您可以使用IN

从 UID 所在的受邀者中删除(从活动中选择 UID)

或者,如果您愿意,您可以使用加入

Delete i
From Invited as i
Join Active as a on i.UID = a.UID 

Yes you can use IN.

Delete From Invited where UID in (Select UID From Active)

Or you can use a Join if you want to

Delete i
From Invited as i
Join Active as a on i.UID = a.UID 
遗弃M 2024-11-15 06:00:09
DELETE FROM `Invited` WHERE Invited.UID IN ( SELECT UID FROM `Active`)

或者,为了提高性能:

DELETE i FROM `Invited` AS i WHERE EXISTS ( SELECT 1 FROM `Active` WHERE Active.UID = i.UID )
DELETE FROM `Invited` WHERE Invited.UID IN ( SELECT UID FROM `Active`)

or, for a performance improvement:

DELETE i FROM `Invited` AS i WHERE EXISTS ( SELECT 1 FROM `Active` WHERE Active.UID = i.UID )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文