# Miscellaneous > SQL Scripts >  Comparing Two Tables

## sql.bhudev

Hi Dear,

This Code will compare Two Tables.
And Filter Records from Table1 which R not existing in Table2. I think will help out.

SELECT 	A.COL1,
	A.COL2,
	A.COL3,
	A.COL4
FROM 	(SELECT COL1,COL2,COL3,COL4 FROM Table1) A
	LEFT OUTER JOIN
	(SELECT COL1,COL2,COL3,COL4 FROM Table2) B
WHERE 	(CASE WHEN A.COL1 = B.COL1 THEN 1 ELSE 2 END) = 2

Thanks & Regards

Bhudev Prakash

----------


## parikhm3

Can you please advice me on what script should  I use to sync procedure to compare and update 2 tables.

So basically i need two sync parts: First is INSERT of what is not yet existing, second one is UPDATE on the appropriate attributes

how would i go about doing that.

Please advice.

Sincerely,
parikhm3.

----------


## rmiao

On which rdbms?

----------


## parikhm3

what do you mean by what RDBMS

----------


## rmiao

Which database system? Oracle, MS SQL or else?

----------


## parikhm3

we are using MS SQL

----------


## flurk118

Do you need to update data or table schemas?

----------


## rmiao

Do you have table schemas? You need sync tables based on whick column?

----------


## MAK

use tablediff utility.

http://www.databasejournal.com/featu...le.php/3594926
or

use 3rd party products like SQLCompare.

----------

