Solved

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

Posted on 2006-06-15
2
723 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

733 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