SQL Select 其中所有相关条目都满足条件

SQL Select where all related entries satisfy condition

Table答:

id | name | type 

Table乙:

id | a_id | structure

其中 A 有很多 B。

我想查询 Table 中所有相关条目的 none B 的结构 = 'successful'

我正在尝试

select a.name
from a
inner join b on a.id = b.a_id where a.type = 'note' and a.id = ALL (Select a_id from B where structure <> 'successful')

但我得到 0 个结果。 (Heroku Dataclips)

示例数据

id | name | type
01 | woof | note
02 | meow | note
03 | who  | free

id | a_id | structure
01 | 01 | open
02 | 01 | draft
03 | 02 | draft
04 | 02 | successful
05 | 02 | open
06 | 03 | open

运行 这个查询应该 return

woof

因为我希望 A 中的所有实体都具有关联类型的注释,但是 none 中的 table B 中的相关条目具有结构 = 'successful'

一个简单的not exists就能满足你的标准?

select a.name
from TableA a
where a.type='note'
and not exists (select * from TableB b where b.a_id=a.id and b.structure='successful')

结果:'woof'