473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Match two tables.

rsrinivasan
221 100+
Hi all,

I am using SQLServer2000. I have two same tables. I want a query to check whether these two tables have same data. How can i check it?

Thanks,
Jul 4 '08 #1
3 1909
amitpatel66
2,367 Expert 2GB
What is the table structure of both the tables? Do you want to compare column by column or by primary key?....

Try something like

SELECT * FROM table1 WHERE primary_column NOT IN (SELECT * FROM table2)
UNION
SELECT * FROM table2 WHERE primary_column NOT IN (SELECT * FROM table1)

THis will give you the records that are there in either of the tables but not in another one
Jul 4 '08 #2
rsrinivasan
221 100+
What is the table structure of both the tables? Do you want to compare column by column or by primary key?....

Try something like

SELECT * FROM table1 WHERE primary_column NOT IN (SELECT * FROM table2)
UNION
SELECT * FROM table2 WHERE primary_column NOT IN (SELECT * FROM table1)

THis will give you the records that are there in either of the tables but not in another one
Both table structure are same and has same data. I just want to check whether any of the data is changed or modified.
Jul 4 '08 #3
ck9663
2,878 Expert 2GB
Try doing this:

Expand|Select|Wrap|Line Numbers
  1. select min(sourcetable) as sourcetable, field1, field2, field3, field4
  2. from
  3. (select 'table1' as sourcetable, field1, field2, field3, field4 from table1
  4. union
  5. select 'table2' as sourcetable, field1, field2, field3, field4 from table2) twotables
  6. group by field1, field2, field3, field4 
  7. having count(*) = 1
  8.  
This will show you all rows that have at least a difference on one column. Remember, all fields that you want to compare should be inside the subqueries (union) and they should match (field1 goes to field1, etc). Just add all the fields on your table as necessary.

Happy coding.

-- CK
Jul 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Frank Maestas | last post by:
Hello, I have two tables "contact_tbl" and "address_tbl". I have a query that compares the email addresses between the two. If a match is found I need to update a specific field in "contact_tbl"...
3
by: William Case | last post by:
I cannot believe I'm having this much trouble doing such a simple thing! I have two tables with identical structure. I can use an A2K select query to show the records in table 1 that match...
4
by: cosmo_canuck | last post by:
I'm wondering why my content and footer tables in this layout don't match the header and menu - even though they're also set to 600 pixels - both the CSS div's and the tables themselves. I can't...
6
by: blue875 | last post by:
A tale of two queries: One query looks like this, and runs fine. We'll call this the "Customer1 query": SELECT Customer1 overall.*, IIf(IsNull(.),0,1) AS IsField, IIf(IsNull(.),0,1) AS...
4
by: jmdaviault | last post by:
I want to do the equivalent of SELECT id from TABLE WHERE text='text' only fast solution I found is: SELECT id,text from TABLE WHERE MATCH(text) AGAINST('value' IN BOOLEAN MODE) HAVING...
7
by: Petepinca | last post by:
I have 2 Access tables. One has a field with a 4 character product id. Example data: "3210". The other table has the same product id's for matching records BUT has leading characters: "RD3210", etc....
5
by: SQL Learner | last post by:
Hi Alex (Kuznetsov) and All, This is to follow up with my last post, "Link two tables using partial word match". How can I UPDATE table using partial word match? How can I write a SQL statement...
1
by: Nick | last post by:
Does anyone know if there is an easy way to compare a row from table a, to a row in table b with the same structure/field names and return those fields which don't match? I have table_a storing...
1
by: socc16e | last post by:
I have an excel sheet that I have imported into SQL 2000 and I need to match the values in one to the values in another and have them output the matching codes to a separate table or file. After...
3
by: mkjame | last post by:
Hi everyone! I am actually coding a php script and I want to return all the values that doesn't have a relation between two tables. Basically I have two tables, one is called users, the other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.