?
Solved

table comparison in Acccess

Posted on 2011-02-10
5
Medium Priority
?
287 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

850 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