Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

Check duplicates from two queries in SQL

We have two tables in the database.


Only new data resides in the A and subsequently go to B after processing.. We want to run a query to check for duplicates between A and B. The odd part is, there is a field named "C:" we need to take out of the script as that field will never be a duplicate value
1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
something like this:
select * from A
where exists(select null from B
   where B.col1 = A.col1
      and B.col2 = A.col2 
     ... etc ...

Open in new window

If you are using the sql 2005 the you can use intersect it will Returns distinct values by comparing the results of two queries.

Please refer the link more about intersect



create table #one(a int,b int, c int)
create table #one2(a int,b int, c int,D INT)

insert into #one values (1,1,1)
insert into #one values (4,2,3)

insert into #one2 values (1,1,1,6)
insert into #one2 values (2,2,3,4)
insert into #one2 values (3,3,3,8)
insert into #one2 values (4,4,4,0)
insert into #one2 values (5,5,5,7)

SELECT A,B,C from #one intersect select A,B,C from #one2

Open in new window

NCollinsBBPAuthor Commented:
This gave me exactly what I needed.  Sorry for the delayed response, as well as for your assistance.


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now