我有2个名为ContentState
和HashedFile
的实体。
ContentState
的每条记录都与HashedFile
相关联,但该关系不是唯一的,因此ContentState
与unique="false"
和{{1}有多对一的关系(因此,2个或更多not-null="true"
个记录可以指向相同的ContentState
)。
我想要做的是从数据库中删除HashedFile
并检查没有ContentState
连接到它们的HashedFile
条记录&删除那些。什么是PostgreSQL查询?
表格列如下:
表ContentStates
:
CONTENT_STATES
等
表id, hashedFileId
:
HASHED_FILES
等
答案 0 :(得分:3)
您可以使用not exists
构建
delete HASHED_FILES as hf
where
not exists (select * from CONTENT_STATES as cs where cs.HashedFileId = h.Id)