我有两个mySQL表,表示在特定期刊上发表的文档:
Documents:
ID Title Journal
1 Monty: A New Study 6
2 New Discoveries about Python 17
3 An Unpublished Document NULL
Journals:
ID Title
6 Journal of Foo
10 Orphans Weekly
17 Journal of Bar
99 Journal of Orphans在这里,"Monty:一项新的研究“发表在Foo杂志上,”关于Python的新发现“发表在著名的期刊”酒吧杂志“上。
问题是,无论出于什么原因,都有一些期刊标题没有相关文档,即#10和#99。我要删除所有没有关联单据的日记帐分录。我想做一些类似的事情:
delete from Journals where id is not one of (select journal from documents where journal is not null) 但我是mySQL的新手,对此深陷其中。
发布于 2013-05-29 13:26:43
DELETE FROM `Journals` AS j WHERE j.ID NOT EXISTS(SELECT Journal FROM `Documents`);或者..。
DELETE FROM `Journals` AS j WHERE j.ID NOT IN (SELECT Journal FROM `Documents`);发布于 2013-05-29 13:29:03
你可以这样做:
delete from Journals where id not in (SELECT Journal from Documents) https://stackoverflow.com/questions/16806068
复制相似问题