从一个 table 中获取数据,如果不是也在另一个中

Getting data from one table if not also in another

我有一个包含两个相关 table 的数据库( 注册)。

我想通过 SQL 查询从 table 中获取时间,这些时间不在 中registrations table(没有注册)。下午 5 点注册,不会在查询中显示 的下午 5 点。

我当前的查询是:

SELECT time FROM `times` WHERE time IN (SELECT time FROM `registrations` WHERE ID IS NOT NULL)

(注册确实有一个 ID)

这与我想要的相反(始终显示,无论是否注册)。 我怎么会得到相反的效果?

你似乎想要not exists:

select t.*
from times t
where not exists (select 1 from regisrations r where r.time = t.time)