开发者

Delete from a table after a lookup on another table - SQL

开发者 https://www.devze.com 2023-03-07 00:14 出处:网络
Hiii I ha开发者_Python百科ve two tables Invited UID [pk] Active UID [pk] I want to delete UID from Invited who is present in Active table

Hiii

I ha开发者_Python百科ve 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 ?


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 


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 )
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号