dbTalk Databases Forums  

How do I find different records in two copies of same table?

comp.database.ms-access comp.database.ms-access


Discuss How do I find different records in two copies of same table? in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
pillbug
 
Posts: n/a

Default How do I find different records in two copies of same table? - 01-07-2004 , 09:32 AM






I am new to SQL and I am hoping this group can help me. While I'm not using
MS Access, I am using Jet and the Microsoft Text Driver through ODBC, it
should be the same language syntax.

What I have are two versions of the same table (really CSV files). I need
to find records that differ between the two tables; I am not interested in
new records that may appear in the new table.

What I really wanted to have work was the following: (id is a unique field
in the files)

SELECT *
FROM "old.txt" AS old
INNER JOIN "new.txt" AS new
ON old.id = new.id
WHERE NOT (
old.field1 = new.field1 AND
old.field2 = new.field2 AND
...
old.field100 = new.field100
)

But this doesn't work for fields in the files that are strings. It seems
that if one or more of the srings is NULL, the comparison operator returns
UNKNOWN rather than FALSE.if only one is NULL or TRUE if both are NULL. The
Text Driver also doesn't allow me to create a procedure, which might help
here. When I try testing like this:

WHERE NOT (
old.field1 <> new.field1 OR
(old.field1 IS NULL AND new.field1 IS NOT NULL) OR
(old.field1 IS NOT NULL AND new.field1 IS NULL)) OR
...

I get "Query Too Complex" errors.

So I tried this crazy thing and it's working, but I don't like the look of
it and was wondering of maybe there is a simpler, more easily maintainable
way of doing this; not to mention the WHERE id IN (...) expression takes
forever to execute. Basically it forms the union of the two tables, any
changed records then stand out as pairs of rows with the same id since Jet
removes duplicate rows. It's those id's that I am interested in displaying.

SELECT *
FROM "new.txt" AS new
WHERE id IN (

SELECT id
FROM (

SELECT
old.id
old.field1,
old.field2,
...,
old.field100
FROM "old.txt" AS old
UNION
SELECT
new.id
new.field1,
new.field2,
...,
new.field100
FROM "new.txt" AS new
INNER JOIN "old.txt" AS old
ON new.id = old.id

)
GROUP BY id
HAVING COUNT(id) > 1

)
GO

Sorry if this is long, but please, if there is an easier way of doing this
I'd really appreciate your help.



Reply With Quote
  #2  
Old   
pillbug
 
Posts: n/a

Default Re: How do I find different records in two copies of same table? - 01-07-2004 , 09:36 AM






Quote:
WHERE NOT (
old.field1 <> new.field1 OR
(old.field1 IS NULL AND new.field1 IS NOT NULL) OR
(old.field1 IS NOT NULL AND new.field1 IS NULL)) OR
...

I get "Query Too Complex" errors.
this should have read

WHERE (
old.field1 <> new.field1 OR
(old.field1 IS NULL AND new.field1 IS NOT NULL) OR
(old.field1 IS NOT NULL AND new.field1 IS NULL)) OR
...




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.