473,385 Members | 1,409 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,385 software developers and data experts.

Compare Trables in database

Being a relative newbie to queries I need assistance coding queries to compare various fields within several tables contained in a single database. Each table is different in structure in that they do not have the same columns. However they do have similar information (e.g. table 1 has CustomerID and CustStatus and table 2 has Client ID and ClientStatus).

I need to create a query that will:
(1) identify if table 1 has a customerID that is not contained in table 2,
(2) identify if table 2 has a client ID that is not contained in table 1, and
(3) identify differences between the CustStatus and ClientStatus fields.

I've tried sample code from the web but have failed miserably. You help is greatly appreciated.

Thanks,
Paul123
Apr 18 '07 #1
2 1227
pks00
280 Expert 100+
U could try the NOT IN. Now I dont use the design view of queries, I prefer the SQL view, so u could try changing this and pasting it into your sql
Im assuming CustomerID and ClientID are the same

1)
SELECT * FROM Table1
WHERE CustomerID NOT IN (SELECT DISTINCT ClientID From table2)

2) reverse of above

SELECT * FROM Table2
WHERE ClientID NOT IN (SELECT DISTINCT CustomerID From table1)

3) identify differences between the CustStatus and ClientStatus fields.
Now this may work, might be a bit slow though.

SELECT table1.*, table2.*
FROM table1, table2
WHERE table1.CustomerID = table2.ClientID
AND table1.CustStatus <> table2.ClientStatus
Apr 20 '07 #2
NeoPa
32,556 Expert Mod 16PB
Using subqueries (as shown by pks00) is very powerful and flexible. You could probably get away with a simple JOINed query here using a LEFT join and selecting items where the linked field Is Null.
Apr 23 '07 #3

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

Similar topics

3
by: Stephen | last post by:
I have to write a .Net application which can compare SQL Databases including things like: - DB structure, PK's, FK's, indexes and types of indexes i.e. should be able to detect if the same index...
1
by: serge | last post by:
Can someone recommend what SQL Database compare tool to use and why? Thank you
2
by: serge | last post by:
Is there a way to compare two databases one being an old database and the second being a new database, I will update the old database's objects to match the new database's objects? Is there SQL...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
4
by: Sunit Joshi | last post by:
Hello All I'm trying to figure out how to do this the best way. Basically, I need to compare DateTime of files across TimeZones. The situation is like this: 1. I have a database say in Korea...
4
by: Gaby | last post by:
Hi all, What is the best way to compare 2 (large) ArrayLists filled with an object. Can you please help me? Gaby
3
by: Benny Ng | last post by:
Dear all, The following is the source. The password is encrypted and saved into the Binary in SQL2K. Now I want to create a new page to compare the existed password and the password that in the...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...

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.