473,804 Members | 3,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join 3 tables together

I have 3 Access 2003 tables:

TableMain

MID PO TE INFO
1 2 3 ABC
2 2 1 EREER
3 1 3 OIUOI
4 3 3 PERE
5 2 2 DFE
TablePerson

PID FIRSTNAME LASTNAME
1 Joe Smith
2 Cal Jones
3 Bill Carson

I can get this output if I query for a MID number such as 3:

Firstname Lastname Firstname2 Lastname2 Info
Joe Smith Bill Carson OIUOI

Here is the query:
SELECT TableMain.MID, TablePerson.PID , TablePerson.FIR STNAME,
TablePerson.LAS TNAME, TablePerson_1.F IRSTNAME, TablePerson_1.L ASTNAME,
TableMain.INFO
FROM TablePerson INNER JOIN (TableMain INNER JOIN TablePerson AS
TablePerson_1 ON TableMain.TE = TablePerson_1.P ID) ON TablePerson.PID
= TableMain.PO
WHERE TableMain.MID=3
Now if I have a third table (called NotesTable) how would I get that
info?
For example if I query for MID number 3, I should get this:
Firstname Lastname Firstname2 Lastname2 Info Notes
Joe Smith Bill Carson OIUOI
other data

Here is NotesTable
NID MID Notes
1 miscl notes here
2 3 other data
3 fan info
Please advise
Nov 27 '07 #1
1 1955
On Nov 27, 1:44 am, "tes...@hotmail .com" <tes...@hotmail .comwrote:
I have 3 Access 2003 tables:

TableMain

MID PO TE INFO
1 2 3 ABC
2 2 1 EREER
3 1 3 OIUOI
4 3 3 PERE
5 2 2 DFE

TablePerson

PID FIRSTNAME LASTNAME
1 Joe Smith
2 Cal Jones
3 Bill Carson

I can get this output if I query for a MID number such as 3:

Firstname Lastname Firstname2 Lastname2 Info
Joe Smith Bill Carson OIUOI

Here is the query:
SELECT TableMain.MID, TablePerson.PID , TablePerson.FIR STNAME,
TablePerson.LAS TNAME, TablePerson_1.F IRSTNAME, TablePerson_1.L ASTNAME,
TableMain.INFO
FROM TablePerson INNER JOIN (TableMain INNER JOIN TablePerson AS
TablePerson_1 ON TableMain.TE = TablePerson_1.P ID) ON TablePerson.PID
= TableMain.PO
WHERE TableMain.MID=3

Now if I have a third table (called NotesTable) how would I get that
info?
For example if I query for MID number 3, I should get this:
Firstname Lastname Firstname2 Lastname2 Info Notes
Joe Smith Bill Carson OIUOI
other data

Here is NotesTable
NID MID Notes
1 miscl notes here
2 3 other data
3 fan info

Please advise
First point are your joins One to Many or Many to Many? -
If they are One to many (MAIN is the parent of PERSON) then MAIN table
should not hold data that belongs to PERSON it should be the other way
round!
PERSON would then hold a MID as a foreign key field from the MAIN to
make the one to many join.
If your join is many to many from MAIN to PERSON or vice versa then to
resolve that correctly you need a link table to do it consisting of
MID and PID which maps All occurences of MAIN to PERSON. The same is
then true for NOTES - If a NOTE can belong to more than one PERSON OR
MAIN? then it is a many to many join and a linker table should be
employed to make the join using MID or is it PID and NID as the
fields.

Most designers would agree that to hold a candidate foreign key field
in a table (NOTES.MID) which is nullable (as you show) breaks far too
many relational rules to be correct. (does MID belong to NOTES - no
because MID is absent from 2 rows are those 2 rows 'complete' No
because they hold nulls in the MID field. For some better explanation
of relational joins have a look at http://support.microsoft.com/kb/289533.

Good luck

I may well be missing your point here but there isn't really enough
detail in your question to comment completely accurately.
Nov 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
482
by: Preston Landers | last post by:
Hello all. I am trying to write a query that "just" switches some data around so it is shown in a slightly different format. I am already able to do what I want in Oracle 8i, but I am having trouble making it work in SQL Server 2000. I am not a database newbie, but I can't seem to figure this one out so I am turning to the newsgroup. I am thinking that some of the SQL Gurus out there have done this very thing a thousand times before...
8
4975
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and also display their corresponding entries in arb, but if there is NO entry in arb I still want it to show up as NULL or something, so that I can get the attention that there IS no language associated with that article.
4
3575
by: ree32 | last post by:
I want to join two tables together but only join the where the column in table 2 (of type date) is the maximum value. Is this possible? Note table 1 is the main table it is also joined to other tables too.
7
2915
by: stabbert | last post by:
I am attempting to join two tables together on two different unix servers. Here is some relevant info about the tables. TABLE 1 Setup ----------------------- DB2 UDB 7.2 EE
2
3077
by: Doug Crowson | last post by:
I have some questions about co-located joins and db partitions. I've heard various things from various people and was looking for confirmation. Assume the following tables and partitioning keys: DEMOG ---------- WHKEY BIGINT NOT NULL -- index and partitioning key FINDNG
3
7559
by: deko | last post by:
From what I understand, an Inner Join narrow the rows selected to the table with the least results... and an Outer Join does the opposite... SELECT qryTxToQ1.Q1Total, qryTxToQ2.Q2Total, qryTxToQ3.Q3Total, qryTxToQ4.Q4Total FROM qryTxToQ4 OUTER JOIN (qryTxToQ3 OUTER JOIN (qryTxToQ1 OUTER JOIN qryTxToQ2 ON qryTxToQ1.TxAcct_ID = qryTxToQ2.TxAcct_ID) ON qryTxToQ3.TxAcct_ID = qryTxToQ2.TxAcct_ID) ON qryTxToQ4.TxAcct_ID = qryTxToQ3.TxAcct_ID;
25
2833
by: Mike MacSween | last post by:
Regular viewers may want to turn off now. This will be an orchestral management system. Musicians and other staff being booked/paid for jobs. A job may contain other jobs, e.g: World Tour contains US leg and Europe leg (and others) US leg contains State tours (and others)
0
1093
by: tricard | last post by:
Good day all, I have four tables that I am attempting to LEFT JOIN together in a query: tblPartNumber (PartNumberID is primary key autonumber) tblPartNumberVendor (PartNumberVendorID is primary key autonumber) tblPartNumberSupplier (PartNumberSupplierID is primary key autonumber) tblPartNumberCost (PartNumberCostID is primary key autonumber) The relationships are as follows:
2
1537
imrosie
by: imrosie | last post by:
Hello, Here's my situation.The main form built on query of 2 tables,customers and orders. You can locate a customer through the unbound combo box built on row query (custid, fname, lname). The main form filters by customerid and it's supporting query works on an inner join: FROM Customers INNER JOIN Orders ON Customers.CustomerID=Orders.CustomerID; currently there are no orders....(my db is new)....I've only added dummy customers to...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.