A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Continued frustration with relationships and queries



 
 
Thread Tools Display Modes
  #1  
Old March 9th, 2010, 06:44 PM posted to microsoft.public.access.gettingstarted
dan
external usenet poster
 
Posts: 1,408
Default Continued frustration with relationships and queries

So I thought I figured out how to create relationships and run queries but
now I am running into a new problem. I will do my best to describe it.

I have a table that I am using from prior months with all the Regions,
Sub-regions, cities, and zipcodes. It has multiple months of data. After I
create a relationship between two tables at the zipcode level I then create a
query to fill in the Region, sub region etc, I end up getting 1000's of
duplicates. The table that I am mapping from has many months of data while
the table i'm mapping to has 1 month. How do i tell access to only map the
information once instead of brining over ever instance of a match?
  #2  
Old March 9th, 2010, 07:36 PM posted to microsoft.public.access.gettingstarted
J_Goddard via AccessMonster.com
external usenet poster
 
Posts: 221
Default Continued frustration with relationships and queries

Hi -

You have not given us much to go on, but it sounds as if your data is not
properly normalized. When you say that a table contains sub-regions, cities
and zip codes, and then say it contains months of data, something isn't right
(I think).

Can you post the basic structure of your tables, and what you want the
relationships to be? You are getting extra rows in your queries because one
of the tables contains many occurances of the same zip code, when you should
only have one.

John


Dan wrote:
So I thought I figured out how to create relationships and run queries but
now I am running into a new problem. I will do my best to describe it.

I have a table that I am using from prior months with all the Regions,
Sub-regions, cities, and zipcodes. It has multiple months of data. After I
create a relationship between two tables at the zipcode level I then create a
query to fill in the Region, sub region etc, I end up getting 1000's of
duplicates. The table that I am mapping from has many months of data while
the table i'm mapping to has 1 month. How do i tell access to only map the
information once instead of brining over ever instance of a match?


--
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201003/1

  #3  
Old March 9th, 2010, 07:58 PM posted to microsoft.public.access.gettingstarted
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Continued frustration with relationships and queries

You appear to be trying to join two tables on non-key columns, i.e. zipcodes,
so the result will that every instance of a zipcode in one table it will join
to every instance of the same zipcode in the other table. This is why so
many rows are returned.

The fundamental problem is that you are storing information redundantly in
incorrectly normalized tables. The tables consequently need decomposing into
related tables.

Postal codes like zip codes are problematic in that, in the short forms
commonly used, they do not generally relate to a single geographical or
administrative unit. While there may be a straightforward hierarchical
'chain' from cities to sub-regions to regions, a postal code may well be
located in than one city or town. This is the case in the UK with the first
part of our alphanumeric postal codes, though not with the full code, and
from previous discussions here I understand the situation to be similar with
zip codes.

So while you can have tables in a set of linear relationship such as:

Cities----Sub-regions----Regions

postal codes do not fit neatly into this set of linear relationships.
Instead there is a many-to-many relationship to cities:

Cities---CityZips----ZipCodes

From which it follows that a CityZips table is needed to model the
relationship. I've assumed that neither a city nor zip code can be in more
than one of your sub-regions, and that a sub-region can only be in one region.


When it comes to storing individual locations in a table, you can see from
the above that a CityID column (not city name as these can legitimately be
duplicated) is all that’s needed as a foreign key in the Locations table.
Sub-region and Region columns in this table would be redundant as these are
determined by the city, so knowing the city is all that's necessary to know
the Sub-region and Region. The introduction of redundancy into the table by
having these columns would leave it open to inconsistent data.

The Locations table, or any table which records specific location data, also
needs a ZipCode column as this is not determined by the city as discussed
above. So you can see that the CityID and ZipCode columns in the Locations
table are in fact a composite primary key referencing the composite primary
key of CityZips, so an enforced relationship can be created between Locations
and CityZips.

Its not as difficult task to decompose an incorrectly normalized table into a
set of correctly normalized tables as might be thought. Essentially it’s a
question of executing a set of 'append' queries to insert rows into each new
table. First a DISTINCT set of Region values would be INSERTed INTO Regions;
then a distinct set of Sub-region and Region values in to Sub-regions; and so
on down the line.

Once you have a set of correctly normalized and related tables, queries will
mirror the relationships. In fact, having created the relationships, when
you add the tables to a query in design view Access will automatically JOIN
them to reflect the relationships.

The other point here is that you appear to have two tables to represent
'data', i.e. the fact that one is for prior months and the other for the
current month. Data should only be represented as values at column positions
in rows in tables (it was Codd's Rule #1, The Information Rule when he first
put forward the relational database model back in 1970). Usually a date/time
column in a single table would do this.

Ken Sheridan
Stafford, England

Dan wrote:
So I thought I figured out how to create relationships and run queries but
now I am running into a new problem. I will do my best to describe it.

I have a table that I am using from prior months with all the Regions,
Sub-regions, cities, and zipcodes. It has multiple months of data. After I
create a relationship between two tables at the zipcode level I then create a
query to fill in the Region, sub region etc, I end up getting 1000's of
duplicates. The table that I am mapping from has many months of data while
the table i'm mapping to has 1 month. How do i tell access to only map the
information once instead of brining over ever instance of a match?


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201003/1

  #4  
Old March 9th, 2010, 08:01 PM posted to microsoft.public.access.gettingstarted
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default Continued frustration with relationships and queries

There's only one practical way for us to know: Show us the SQL. Open the
query in design view. Next go to View, SQL View and copy and past it here.

Information on primary keys and relationships would be a nice touch too.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"Dan" wrote:

So I thought I figured out how to create relationships and run queries but
now I am running into a new problem. I will do my best to describe it.

I have a table that I am using from prior months with all the Regions,
Sub-regions, cities, and zipcodes. It has multiple months of data. After I
create a relationship between two tables at the zipcode level I then create a
query to fill in the Region, sub region etc, I end up getting 1000's of
duplicates. The table that I am mapping from has many months of data while
the table i'm mapping to has 1 month. How do i tell access to only map the
information once instead of brining over ever instance of a match?

 




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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.