如何在两个表中提取非重复值(How to extract non

编程入门 行业动态 更新时间:2024-10-22 09:53:16
如何在两个表中提取非重复值(How to extract non-duplicate values in two tables)

我有两个表,每个表包含带数字的列。 我需要比较两个表中的列并提取第一个表中存在的数字,而不是第二个表中存在的数字。 我不需要独特的价值。

我写了这个查询:

SELECT Table1.Numbers, Table1.Name FROM Table1, Table2 WHERE Table1.Numbers != Table2.numbers

由于我正在处理数百万条记录,有人可以推荐更有效的查询,这会给我提供相同的结果吗?

I have two tables where each one contains columns with numbers. I need to compare columns in both tables and extract the number that does exist in first table, and does not exist in second one. I don't need unique value.

I wrote this query:

SELECT Table1.Numbers, Table1.Name FROM Table1, Table2 WHERE Table1.Numbers != Table2.numbers

Since I am working on several million records can someone recommend more efficient query which would provide me with identical results?

最满意答案

我会使用NOT EXISTS :

SELECT Table1.Numbers, Table1.Name FROM Table1 WHERE NOT EXISTS( SELECT 1 FROM Table2 WHERE Table1.Numbers=Table2.Numbers )

其他方法:

我应该使用NOT IN,OUTER APPLY,LEFT OUTER JOIN,EXCEPT还是NOT EXISTS?

I would use NOT EXISTS:

SELECT Table1.Numbers, Table1.Name FROM Table1 WHERE NOT EXISTS( SELECT 1 FROM Table2 WHERE Table1.Numbers=Table2.Numbers )

Other approaches:

Should I use NOT IN, OUTER APPLY, LEFT OUTER JOIN, EXCEPT, or NOT EXISTS?

更多推荐

本文发布于:2023-08-02 18:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   如何在   extract

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!