Solved

URGENT: Query to view data from table A minus table B.

Posted on 2006-06-15
2
722 Views
Last Modified: 2012-06-21
Hi, I would like to make a query that will give me rows from table A excluding the rows in table B.  Both tables have the same structure.

I know I can use something like below, but I need to do a join on each field (I have 20 fields).  The problem I am having is that some of these fields may be null on various rows, so a comparison of A.field1 = B.field1 does not work.

Example:
SELECT Table2.*
FROM Table2 LEFT JOIN Table1 ON (Table2.d = Table1.d) AND (Table2.c =
Table1.c) AND (Table2.b = Table1.b) AND (Table2.a = Table1.a) AND
(Table2.Field1= Table1.Field1)
WHERE (((Table1.Field1) Is Null));

I am using MS Access 2000, and can use VBA to help do this if necessary - but I would like to avoid using Access specific commands/features since I would like to migrate to another system in the near future.  Can someone provide me a fairly simple solution.

Thanks.
0
Comment
Question by:shamstar
2 Comments
 
LVL 25

Accepted Solution

by:
jrb1 earned 500 total points
ID: 16911833
When you do your join in the above query, you can use the nz function (in access, but there is an equivalent in sql server and oracle) to convert the null value.

Wrap the comparison values in the "nz" function:

SELECT Table2.*
FROM Table2 LEFT JOIN Table1 ON (nz(Table2.d) = nz(Table1.d)) AND (nz(Table2.c) =
nz(Table1.c)) AND (nz(Table2.b) = nz(Table1.b)) AND (nz(Table2.a) = nz(Table1.a)) AND
(nz(Table2.Field1)= nz(Table1.Field1))
WHERE (Table1.Field1 Is Null);
0
 
LVL 8

Author Comment

by:shamstar
ID: 16911931
Thats fantastic, exactly the type of answer I needed.

Thanks for your help jrb1!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some very basic things about SQL Server filegroups.
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question