PC Review


Reply
Thread Tools Rate Thread

DEFINING RELATIONSHIP BETWEEN TWO or more TABLES

 
 
pago_boss@yahoo.com.au
Guest
Posts: n/a
 
      27th Mar 2007


I am often required to design queries involving two or more tables and
linking them together. However, in linking them together, i am often
forced to define the relationship (join properties) between these
tables and I often get it wrong. As a result, i get duplicate records
all the time. Can anyone explain to me how does one-to-many and many-
to-many relationship really works in Access queries and how are they
being retrieved. And how can i easily identify and fix this probem.

Plese give some examples.

Thanks,

Pago

 
Reply With Quote
 
 
 
 
Jamie Collins
Guest
Posts: n/a
 
      27th Mar 2007
On Mar 27, 8:23 am, pago_b...@yahoo.com.au wrote:
> I am often required to design queries involving two or more tables and
> linking them together. However, in linking them together, i am often
> forced to define the relationship (join properties) between these
> tables and I often get it wrong. As a result, i get duplicate records
> all thetime. Can anyone explain to me how does one-to-many and many-
> to-many relationship really works in Access queries and how are they
> being retrieved. And how can i easily identify and fix this probem.
>
> Plese give some examples.


I went on an Access course some <coughs> years ago and this really
confused the &%@£ out of me, too; about six month later, I'm at a
client's site configuring some tables in SQL Server and I suddenly had
this Eureka moment and realized what the teacher was trying to
convey...

I think the problem is there are two concepts that get merged into
one. Consider your SQL DLL (your schema i.e. tables) and your SQL DML
(how you use those tables to manage data e.g. returning a resultset of
data).

In SQL DDL, you can create a FOREIGN KEY so that one table REFERENCES
another.

In SQL DML. you can create a JOIN between two tables. IIRC the three
JOIN types supported in the query builder tool thing are INNER JOIN,
LEFT JOIN and RIGHT JOIN.

[
FWIW something I realized quickly but took a while to confirm is that

Table1 LEFT JOIN Table2 ON <join condition>

is logically equivalent to

Table2 RIGHT JOIN Table1 ON <join condition>
]

It is usually the case that the columns used in REFERENCES in the SQL
DDL are the ones that will be used to created table joins in the SQL
DML (the query builder will assume this by default) but it doesn't
have to be this way.

My suggestion would be to research the SQL keywords (uppcase) I've
mentioned above and learn how to write simple queries including JOINs
using SQL e.g. try http://www.sqlcourse.com/.

Bear in mind that the query builder tool is writing SQL and to get the
most out of it you will do well to understand the basic format of a
query (though you may find that once you know how you will prefer to
write your SQL queries yourself <g>). Also, Access uses the term
'Relationships' for FOREIGN KEYs although the Access definition is
looser by design.

Some hints:

"Here is how a SELECT works in SQL ... at least in theory..."
http://groups.google.com/group/micro...9592725f2d4685

"Here is how OUTER JOINs work in SQL-92..."
http://groups.google.com/group/micro...771ad2197c3117

Jamie.

--


 
Reply With Quote
 
=?Utf-8?B?c2N1YmFkaXZlcg==?=
Guest
Posts: n/a
 
      28th Mar 2007

Go to tools -> relationships, display the tables then drag the appropriate
fields between tables to establish the relationship.

When you set show the tables in the query the relationships will show. But
remember the tables will only show as many records as the two tables have
recorded (if that makes sense)

"(E-Mail Removed)" wrote:

>
>
> I am often required to design queries involving two or more tables and
> linking them together. However, in linking them together, i am often
> forced to define the relationship (join properties) between these
> tables and I often get it wrong. As a result, i get duplicate records
> all the time. Can anyone explain to me how does one-to-many and many-
> to-many relationship really works in Access queries and how are they
> being retrieved. And how can i easily identify and fix this probem.
>
> Plese give some examples.
>
> Thanks,
>
> Pago
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assistance in defining relationship between tables =?Utf-8?B?TWF0dA==?= Microsoft Access Database Table Design 1 26th Jan 2006 01:49 AM
creating/defining relationship between two tables =?Utf-8?B?R2l6?= Microsoft Access Getting Started 2 18th Apr 2005 09:24 PM
Defining fields when creating a relationship =?Utf-8?B?RGF2aWQ=?= Microsoft Access Form Coding 1 3rd Jun 2004 06:33 AM
Problem with Defining Relationship and then an appropriate Query Mike Webb Microsoft Access Getting Started 3 15th Dec 2003 02:29 PM
I'm having hard time defining relationship -help please Mike Microsoft Access Forms 2 31st Oct 2003 04:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:05 PM.