与内连接查询相反

发布于 2024-09-29 04:32:06 字数 121 浏览 9 评论 0原文

表 1 2 列:ID、名称

表 2 2 列:ID、名称

用于显示表 1 中但不在表 2 中的名称的查询是什么?因此,过滤掉表 1 中表 2 中的所有名称即可得到结果查询。过滤是根据 ID 而不是名称。

Table 1 2 columns: ID, Name

Table 2 2 columns: ID, Name

What is a query to show names from Table 1 that are not in table 2? So filtering out all the names in table 1 that are in table 2 gives the result query. Filtering is on ID not name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

坦然微笑 2024-10-06 04:32:06
Select * from table1
left join table2 on table1.id = table2.id
where table2.id is null
Select * from table1
left join table2 on table1.id = table2.id
where table2.id is null
计㈡愣 2024-10-06 04:32:06

这应该比 left join...is null 版本表现得更好。请参阅这里此处进行比较。

select t1.id, t1.name
    from table1 t1
    where not exists(select null from table2 t2 where t2.id = t1.id)

This should perform better than the left join...is null version. See here and here for comparisons.

select t1.id, t1.name
    from table1 t1
    where not exists(select null from table2 t2 where t2.id = t1.id)
盗琴音 2024-10-06 04:32:06

使用此查询

select
t1.*
from table1 t1
left outer join table2 t2
on t1.id=t2.id
where t2.id is null

可以将 t1 中的所有内容连接到 t2 中存在的内容。 where 子句过滤掉 t2 中不存在的所有记录。

Use this query

select
t1.*
from table1 t1
left outer join table2 t2
on t1.id=t2.id
where t2.id is null

this works by joining everything in t1 to whatever exists in t2. the where clause filters out all of the records that don't exist in t2.

寄居人 2024-10-06 04:32:06
SELECT Table1.ID, Table1.Name, Table2.ID 
FROM Table1 LEFT OUTER JOIN Table2 ON Table1.ID = Table2.ID 
WHERE Table2.ID IS NULL 

我认为应该这样做。

SELECT Table1.ID, Table1.Name, Table2.ID 
FROM Table1 LEFT OUTER JOIN Table2 ON Table1.ID = Table2.ID 
WHERE Table2.ID IS NULL 

I think that should do it.

绅士风度i 2024-10-06 04:32:06

尝试这样:

select t1.*
from table1 as t1
where t1.id not in 
  (select distinct t2.id from table2 as t2);

Try like this:

select t1.*
from table1 as t1
where t1.id not in 
  (select distinct t2.id from table2 as t2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文