如何排除不与另一个表连接的行? [英] How to exclude rows that don't join with another table?

查看:13
本文介绍了如何排除不与另一个表连接的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张表,一张有主键,另一张是外键.

I have two tables, one has primary key other has it as a foreign key.

我想从主表中提取数据,只有当辅助表没有有包含它的键的条目时.与简单的内连接相反,它只返回通过该键连接在一起的行.

I want to pull data from the primary table, only if the secondary table does not have an entry containing it's key. Sort of an opposite of a simple inner join, which returns only rows that join together by that key.

推荐答案

SELECT <select_list> 
FROM Table_A A
LEFT JOIN Table_B B
ON A.Key = B.Key
WHERE B.Key IS NULL

加入的完整图像

来自文章:http://www.codeproject.com/KB/database/Visual_SQL_Joins.aspx

这篇关于如何排除不与另一个表连接的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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