在SQL中查找多个表中的常见用户 [英] Find common users in multiple tables in SQL

查看:51
本文介绍了在SQL中查找多个表中的常见用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 5 张桌子.

我想在表 1、2 和 3 中获取不在表 4 和 5 中的普通用户.

I want to get common users in table 1, 2 and 3 that are not in table 4 and 5.

有人可以帮我吗:)

表格

table1(userid,discount)

table2(userid,discount)

table3(userid,discount)

table4(userid,discount)

table5(userid,discount)

推荐答案

一种方式,左连接表行省略:

One way, left join on the table rows to omit:

select *
from   table1 a
join   table2 b on (a.userid = b.userid)
join   table3 c on (a.userid = c.userid)
left join table4 d on (a.userid = d.userid)
left join table5 e on (a.userid = e.userid)
where d.userid is null and e.userid is null;

这篇关于在SQL中查找多个表中的常见用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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