我有 2 个名为 ContentState
和 HashedFile
的实体。
ContentState
的每条记录都有一个 HashedFile
链接到它,但关系不是唯一的,因此关于 ContentState
和 unique="false"
和 not-null="true"
(因此,2 个或多个 ContentState
记录可以指向相同的 HashedFile
)。
我想做的是从数据库中删除一个 ContentState
并检查没有 ContentStates
连接到它们的 HashedFile
记录并删除那些也是。对此的 PostgreSQL 查询是什么?
表格列如下:
表CONTENT_STATES
:
id, hashedFileId
等
表HASHED_FILES
:
id
等
最佳答案
可以使用not exists
构造
delete HASHED_FILES as hf
where
not exists (select * from CONTENT_STATES as cs where cs.HashedFileId = h.Id)
关于sql - 选择没有指针的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18286227/