这个简单的 SQL Select 语句有问题 [英] Having trouble with this simple SQL Select statement

查看:19
本文介绍了这个简单的 SQL Select 语句有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张桌子,A 和 B.

I have two tables, A and B.

两者都具有完全相同的列.

Both have the exact same columns.

我需要选择 TableA 中所有不是在 TableB 中的项目.

I need to select all the items in TableA that ARE NOT in TableB.

这是十字路口吧?我该怎么做?

This is intersection, right? How can I do this?

推荐答案

假设 TableA 和 TableB 有一个名称为 id 的主键.

assuming TableA and TableB have a primary key of name id.

select TableA.* 
  from TableA 
left outer join TableB on TableB.id = TableA.id
where TableB.id is null;

这将查找表 b 没有表 a 的 id 实例的所有条目.

This will find all entries where table b does not have an instance of table a's id.

这篇关于这个简单的 SQL Select 语句有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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