Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello, I have 2 tables that have

Status
Not open for further replies.

wdu94

Programmer
Aug 15, 2001
61
0
0
US
Hello,

I have 2 tables that have the same field names but different table name. These 2 tables have a lot of same data inside. I want to know how to check if these 2 tables acctually the same or not. if these 2 table have the different data, I need to merge in one and cut dupliate data. Thank you very much for your help.

Jeannia
 
Select Count(*) from tablea

Keep track of the answer

select * from tablea
union distinct select * from tableb

if the number of records selected is exactly the same as the first answer then all the records in tableb are identical to some record in tablea.

 

Extending fluteplr's solution a bit, you can identify the records that don't match with the following query. This assumes there is some sort of identity or primary key on each table.

Select KeyCol From
(select * from tablea
union
select * from tableb) As q
Group By KeyCol
Having count(*) > 1

Using the key identified in the above query, you can select records from the two tables for updating or deleting. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top