Solved

table comparison in Acccess

Posted on 2011-02-10
5
225 Views
Last Modified: 2012-05-11
I have 2 tables (A and B) with the same structure, what is the easiest way to obtain a list of combined record without double counting the row with the same record in a chosen field?
0
Comment
Question by:fitaliano
  • 2
  • 2
5 Comments
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34864459
A union query should do it:


SELECT *
FROM tblContacts
UNION SELECT * FROM tblMoreContacts;

Open in new window

0
 

Author Comment

by:fitaliano
ID: 34864510
How do I ensure that Last Names are not double-counted?
0
 
LVL 77

Expert Comment

by:peter57r
ID: 34864825
Union will eliminate duplicates but the duplication is based on all selected fields.
If you want to base duplication just on one field then you will have to come up with some rules about how you decide which record to keep and which to remove.  You will probably then need a second process to get the final list.
0
 

Author Comment

by:fitaliano
ID: 34864913
Thanks Peter,

can you be more specific?

This is exactly what I would like to do:

I have [Address] and [Last Name] in both table A and B.

I want to obtain a list that combines both tables where the same [Last Name] in A and B is counted only once.  If there is a match between [Last Name] I want table A to win


0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 34870324
In that case use your equivalent of...

Select * from tableA
Union
Select * from TableB as B where  not exists (Select Lastname from tableA where TableA.Lastname = B.Lastname)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now