我有 2 个表(AllClients 和 AllActivities),需要检索以下信息:
我需要一份没有相关事件的客户列表。
这是我的表格,其中包含一些虚假数据以帮助解释我正在寻找的内容:
我基本上需要 sql 来检索 Sam Johnson,因为他没有事件,而且他的 TypeCode 为“P”。
最佳答案
你不一定需要加入
select *
from AllClients c
where TypeCode = 'P'
and not exists (select 1 from AllActivities a where a.LookupCode = c.LookupCode)
关于mysql - 不确定要使用哪个 SQL 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19320603/