JZeig
asked on
Query base on Many-to-Many relationship
Customer Table: tblCustID(AutoN); tblCustFName(Text); tblCustLName(Text); tblCustLocal(Number)
frmCustomerInfo: tblCustID; tblCustFName; tblCustLName; these are text boxes
tblCusLocal(ComboBox) Properties: SELECT tblLocal.tblLocalID, tblLocal.tblLocalName, tblOrganization.tblOrganiz ationName FROM tblLocal INNER JOIN tblOrganization ON tblLocal.tblLocalID=tblOrg anization. [tblOrgani zationLoca l];
frmOrders: tblOrdersDate(Date) TextBox; tblOrdersSeason(text) ComboBox; tblOrdersID(Auto)TextBox; tblOrdersCustID(text)Combo Box... There is a subForm that contain products purchased.
Here's my problem - when I run the query do display the orders sorted by customer and organization I get duplicate records for each customer cause each location has multiple organizations and to get from the tblcustomer to the tblorganization, I have to go through the tbllocal
(one-to-many betwn tblcustomer and tblorganization where tbllocal is the one in both relationships).
The results give me locals plus all the organization that that local has associated with it for each customer, but if you examine the above info in up top, U can C that, when I enter the customer info in the frmCustomer, I pick a specific local/organization combination. I know I'm leaving out some info, but I figure this is a good way to start.
frmCustomerInfo: tblCustID; tblCustFName; tblCustLName; these are text boxes
tblCusLocal(ComboBox) Properties: SELECT tblLocal.tblLocalID, tblLocal.tblLocalName, tblOrganization.tblOrganiz
frmOrders: tblOrdersDate(Date) TextBox; tblOrdersSeason(text) ComboBox; tblOrdersID(Auto)TextBox; tblOrdersCustID(text)Combo
Here's my problem - when I run the query do display the orders sorted by customer and organization I get duplicate records for each customer cause each location has multiple organizations and to get from the tblcustomer to the tblorganization, I have to go through the tbllocal
(one-to-many betwn tblcustomer and tblorganization where tbllocal is the one in both relationships).
The results give me locals plus all the organization that that local has associated with it for each customer, but if you examine the above info in up top, U can C that, when I enter the customer info in the frmCustomer, I pick a specific local/organization combination. I know I'm leaving out some info, but I figure this is a good way to start.
List few records of the table, and show the required output.
Here some info, hope to be helpful.
M-M relation means you have left table(L_ID, ...) and right table(R_ID,...)
the M-M will be a link table between the two (L_ID, R_ID, ....)
Having only the M-M table, you may create 2 queries to represent the left and right tables.
For Left table: LQ (Select Distinct L_ID, ... FROM [M-M] )
For tight table: RQ (Select Distinct R_ID, ... FROM [M-M])
Now you have three tables, LQ, RQ, and [M-M].
Here some info, hope to be helpful.
M-M relation means you have left table(L_ID, ...) and right table(R_ID,...)
the M-M will be a link table between the two (L_ID, R_ID, ....)
Having only the M-M table, you may create 2 queries to represent the left and right tables.
For Left table: LQ (Select Distinct L_ID, ... FROM [M-M] )
For tight table: RQ (Select Distinct R_ID, ... FROM [M-M])
Now you have three tables, LQ, RQ, and [M-M].
ASKER
Here are the relationships - this might help
tblOrders: tblOrdersCustID----------- ------- tblCustomer: tblCustID
within same table "tblCustomer"
tblCustomer: tblCustLocal -------------------------- ---------- -----
-------------------------- ----tblLoc al: tblLocalID
within same table "tblLocal"
tblLocal: tblLocalID---------------- -----tblOr ganization : tblOrganizationLocal
U have query up top. The desired outcome is only the orders for a specific organization. If a specific "Local" has multiple "Organization"s, I get duplicates. I think I need to link the organization first then that way the organization will default to the correct local. "Local"s have multiple organizations, but the organization is restricted to a specific local. which I have setup but I think this backwards.
tblOrders: tblOrdersCustID-----------
within same table "tblCustomer"
tblCustomer: tblCustLocal --------------------------
--------------------------
within same table "tblLocal"
tblLocal: tblLocalID----------------
U have query up top. The desired outcome is only the orders for a specific organization. If a specific "Local" has multiple "Organization"s, I get duplicates. I think I need to link the organization first then that way the organization will default to the correct local. "Local"s have multiple organizations, but the organization is restricted to a specific local. which I have setup but I think this backwards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
to do this you need a third table ( i think from what you describe, it is the local table )
anyway, see this demo
http://office.microsoft.com/en-us/access-help/demo-set-the-relationship-between-two-tables-HA010254901.aspx?pid=CH100739911033