紧急:返回表之间的重复记录 [英] Urgent: returning duplicate records between tables
问题描述
您好b $ b
我迫切需要一种方法在两张桌子中选择重复记录。
表1有A列和B列,有大约4000条记录
表2有A列和B列,有大约8000条记录
我想选择全部两个表中B都有重复值的记录。
以下查询应该有效,但产生20000条记录显然非常不正确。
Hi
I'm in urgent need of a way to select duplicate records in two tables.
Table1 has columns A and B and has around 4000 records
Table2 has columns A and B and has around 8000 records
I want to select all records which have a duplicate value for B in both tables.
The following query should work but produces 20000 records which is obviously wildly incorrect.
select Table1.A, Table1.B FROM Table1, Table2 WHERE Table1.B = Table2.B
我的尝试:
.................... .................................................. ..........................................
What I have tried:
................................................................................................................
推荐答案
使用 SQL INNER JOIN [ ^ ]
我认为B的相同值可以重复多次。检查这种情况的一种方法是使用EXISTS
子句。
例如:
I take it that the same value for B can be repeated multiple times. One way to check this could be to useEXISTS
clause.
For example:
SELECT *
FROM Table1 t1
WHERE EXISTS (SELECT 1
FROM Table2 t2
WHERE t2.B = t1.B)
这篇关于紧急:返回表之间的重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!