如何从联接的左侧获取联接表中不存在的记录? [英] How do I get the records from the left side of a join that do not exist in the joined table?

查看:51
本文介绍了如何从联接的左侧获取联接表中不存在的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接表b的表,我只希望表a中的记录不存在在表b中.

I have table a joining table b, I only want the records from table a that do not exist in table b.

我的部分查询是:

SELECT DISTINCT u.id, u.lastname
FROM user u
LEFT JOIN context ct
ON ct.userid = u.id

谢谢.

推荐答案

select distinct u.id,
    u.lastname
from user u
left join context ct on ct.userid = u.id
where ct.userid is null

这篇关于如何从联接的左侧获取联接表中不存在的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆