Please Help This Idiot - Records Quadrupling!

R

Ross

Hi,
Sorry for not being able to understand my problem fully. I'm hoping
someone can help. I am trying to create a recordset from a query to
display customer workorders, parts used, the employee who serviced the
account and amounts to be billed. The results are to be formatted as
per customer request and exported to an Excel spreadsheet.

Here are the tables and fields I am using to build this query:

tbl_Customers
tbl_Customers.FirstName
tbl_Customers.LastName
tbl_Customers.HomePhone

tbl_Employees
tbl_Employees.FirstName
tbl_Employees.LastName

tbl_Workorders
tbl_Workorders.WorkorderID <- primary key
tbl_Workorders.AccountNumber
tbl_Workorders.InstallDate

tbl_WO_Parts
tbl_WO_Parts.PartID
tbl_WO_Parts.SerialNumber

tbl_WO_ClaimAmt
tbl_WO_ClaimAmt.ClaimCode
tbl_WO_ClaimAmt.RequestType
tbl_WO_ClaimAmt.ClaimAmount

When I create the query using both tbl_WO_ClaimAmt and tbl_WO_Parts,
the records returned appear to have quadrupled for each customer.
Running the query with ONLY tbl_WO_Parts and the other tables(omitting
tbl_WO_Claim) returns the correct amount of records for each customer.
Running the query with ONLY tbl_WO_Claim and the other tables(omitting
tbl_WO_Parts) returns the correct amount of records for each customer.
As soon as I add both of these tables to the query is when the record
duplication occurs.

Here is the SQL, I hope it will be helpful:

SELECT DISTINCTROW tbl_WorkorderParts.PartID,
tbl_WorkorderParts.SerialNumber, tbl_Customers.[First Name],
tbl_Customers.[Last Name], tbl_Customers.[Home Phone],
tbl_MIGWorkorder.[Install Date], tbl_Employees.FirstName,
tbl_Employees.LastName, tbl_MIGWorkorder.AccountNum,
tbl_WorkOrderClaimAmt.ClaimCode, tbl_WorkOrderClaimAmt.RequestType,
tbl_WorkOrderClaimAmt.ClaimAmount
FROM (tbl_Employees INNER JOIN ((tbl_Customers INNER JOIN
tbl_MIGWorkorder ON tbl_Customers.CustomerID =
tbl_MIGWorkorder.CustomerID) LEFT JOIN tbl_WorkOrderClaimAmt ON
tbl_MIGWorkorder.WorkOrderID = tbl_WorkOrderClaimAmt.WorkOrderID) ON
tbl_Employees.EmployeeID = tbl_MIGWorkorder.EmployeerID) INNER JOIN
tbl_WorkorderParts ON tbl_MIGWorkorder.WorkOrderID =
tbl_WorkorderParts.WorkorderID;

I'm not sure if the order I've added the fields makes a difference
here, but this is how the client wants the data to appear. (The client
BTW is a close friend of mine so I hope you can understand why he
asked a newb like me to do this ;-)

Each workorder only has 1 CustomerID and 1 WorkorderID, but as you can
imagine many different parts and serial numbers and many different
claim codes and prices can be associated to 1 customer.
So we might have something like:

WorkOrderID
CustomerName
AccountNumber
PartID1
PartID2
PartID3
SerialNum1
SerialNum2
SerialNum3
ClaimCode1
ClaimCode2
ClaimCode3
ClaimAmount1
ClaimAmount2
ClaimAmount3

As noted earlier omitting either the tbl_Parts or tbl_ClaimAmt from
the query produces the correct results. But as soon as both
tables.fields are used the records quadruple. This is probably
something quite simple for you gurus out there, but as the subject
says, I'm an idiot ;-)

TIA to anyone who replies.

Best Regards,
Ross
 
A

Amy Blankenship

I don't think you can have left joins inside inner joins. If this is what
you need, create separate left join queries, then use another query to join
them in an inner join.

HTH;

Amy

Ross said:
Hi,
Sorry for not being able to understand my problem fully. I'm hoping
someone can help. I am trying to create a recordset from a query to
display customer workorders, parts used, the employee who serviced the
account and amounts to be billed. The results are to be formatted as
per customer request and exported to an Excel spreadsheet.

Here are the tables and fields I am using to build this query:

tbl_Customers
tbl_Customers.FirstName
tbl_Customers.LastName
tbl_Customers.HomePhone

tbl_Employees
tbl_Employees.FirstName
tbl_Employees.LastName

tbl_Workorders
tbl_Workorders.WorkorderID <- primary key
tbl_Workorders.AccountNumber
tbl_Workorders.InstallDate

tbl_WO_Parts
tbl_WO_Parts.PartID
tbl_WO_Parts.SerialNumber

tbl_WO_ClaimAmt
tbl_WO_ClaimAmt.ClaimCode
tbl_WO_ClaimAmt.RequestType
tbl_WO_ClaimAmt.ClaimAmount

When I create the query using both tbl_WO_ClaimAmt and tbl_WO_Parts,
the records returned appear to have quadrupled for each customer.
Running the query with ONLY tbl_WO_Parts and the other tables(omitting
tbl_WO_Claim) returns the correct amount of records for each customer.
Running the query with ONLY tbl_WO_Claim and the other tables(omitting
tbl_WO_Parts) returns the correct amount of records for each customer.
As soon as I add both of these tables to the query is when the record
duplication occurs.

Here is the SQL, I hope it will be helpful:

SELECT DISTINCTROW tbl_WorkorderParts.PartID,
tbl_WorkorderParts.SerialNumber, tbl_Customers.[First Name],
tbl_Customers.[Last Name], tbl_Customers.[Home Phone],
tbl_MIGWorkorder.[Install Date], tbl_Employees.FirstName,
tbl_Employees.LastName, tbl_MIGWorkorder.AccountNum,
tbl_WorkOrderClaimAmt.ClaimCode, tbl_WorkOrderClaimAmt.RequestType,
tbl_WorkOrderClaimAmt.ClaimAmount
FROM (tbl_Employees INNER JOIN ((tbl_Customers INNER JOIN
tbl_MIGWorkorder ON tbl_Customers.CustomerID =
tbl_MIGWorkorder.CustomerID) LEFT JOIN tbl_WorkOrderClaimAmt ON
tbl_MIGWorkorder.WorkOrderID = tbl_WorkOrderClaimAmt.WorkOrderID) ON
tbl_Employees.EmployeeID = tbl_MIGWorkorder.EmployeerID) INNER JOIN
tbl_WorkorderParts ON tbl_MIGWorkorder.WorkOrderID =
tbl_WorkorderParts.WorkorderID;

I'm not sure if the order I've added the fields makes a difference
here, but this is how the client wants the data to appear. (The client
BTW is a close friend of mine so I hope you can understand why he
asked a newb like me to do this ;-)

Each workorder only has 1 CustomerID and 1 WorkorderID, but as you can
imagine many different parts and serial numbers and many different
claim codes and prices can be associated to 1 customer.
So we might have something like:

WorkOrderID
CustomerName
AccountNumber
PartID1
PartID2
PartID3
SerialNum1
SerialNum2
SerialNum3
ClaimCode1
ClaimCode2
ClaimCode3
ClaimAmount1
ClaimAmount2
ClaimAmount3

As noted earlier omitting either the tbl_Parts or tbl_ClaimAmt from
the query produces the correct results. But as soon as both
tables.fields are used the records quadruple. This is probably
something quite simple for you gurus out there, but as the subject
says, I'm an idiot ;-)

TIA to anyone who replies.

Best Regards,
Ross
 
R

Ross

I don't think you can have left joins inside inner joins. If this is what
you need, create separate left join queries, then use another query to join
them in an inner join.

HTH;

Amy

Thanks for your reply Amy. I'm not sure I need left joins or not, only
that the recordset is displaying 4x as many records as it should.
Following your advice I created 2 queries with tbl_MIGWOrkorder and
tbl_ClaimAmt created a left join, tbl_MIGWOrkorder and tbl_Parts and
created a left join. I then used those queries in a new query to try
and display the results I'm looking for. Unfortunately I must be doing
something wrong because the results are still the same. Here is the
SQL if it helps:

SELECT DISTINCTROW tbl_Customers.[First Name], tbl_Customers.[Last
Name], tbl_Customers.[Home Phone], qry_Parts_Left_Join.PartID,
qry_Parts_Left_Join.SerialNumber, tbl_MIGWorkorder.[Install Date],
tbl_Employees.FirstName, tbl_Employees.LastName,
tbl_MIGWorkorder.AccountNum, qry_ClaimAmt_Left_Join.ClaimCode,
qry_ClaimAmt_Left_Join.RequestType,
qry_ClaimAmt_Left_Join.ClaimAmount, qry_ClaimAmt_Left_Join.cxPaid
FROM ((tbl_Customers INNER JOIN (tbl_Employees INNER JOIN
tbl_MIGWorkorder ON tbl_Employees.EmployeeID =
tbl_MIGWorkorder.EmployeerID) ON tbl_Customers.CustomerID =
tbl_MIGWorkorder.CustomerID) INNER JOIN qry_ClaimAmt_Left_Join ON
tbl_MIGWorkorder.WorkOrderID = qry_ClaimAmt_Left_Join.WorkOrderID)
INNER JOIN qry_Parts_Left_Join ON tbl_MIGWorkorder.WorkOrderID =
qry_Parts_Left_Join.WorkorderID;


I'm not sure if I created the left-join queries correctly, perhaps it
would help if you saw the SQL for those:

SELECT tbl_WorkorderParts.PartID, tbl_WorkorderParts.SerialNumber,
tbl_MIGWorkorder.WorkOrderID
FROM tbl_MIGWorkorder LEFT JOIN tbl_WorkorderParts ON
tbl_MIGWorkorder.WorkOrderID = tbl_WorkorderParts.WorkorderID;

And:

SELECT tbl_WorkOrderClaimAmt.ClaimCode,
tbl_WorkOrderClaimAmt.RequestType, tbl_WorkOrderClaimAmt.ClaimAmount,
tbl_WorkOrderClaimAmt.cxPaid, tbl_MIGWorkorder.WorkOrderID
FROM tbl_MIGWorkorder LEFT JOIN tbl_WorkOrderClaimAmt ON
tbl_MIGWorkorder.WorkOrderID=tbl_WorkOrderClaimAmt.WorkOrderID;

I'm completely stuck, any help you could provide me would be greatly
appreciated.

Best Regards,
Ross



Ross said:
Hi,
Sorry for not being able to understand my problem fully. I'm hoping
someone can help. I am trying to create a recordset from a query to
display customer workorders, parts used, the employee who serviced the
account and amounts to be billed. The results are to be formatted as
per customer request and exported to an Excel spreadsheet.

Here are the tables and fields I am using to build this query:

tbl_Customers
tbl_Customers.FirstName
tbl_Customers.LastName
tbl_Customers.HomePhone

tbl_Employees
tbl_Employees.FirstName
tbl_Employees.LastName

tbl_Workorders
tbl_Workorders.WorkorderID <- primary key
tbl_Workorders.AccountNumber
tbl_Workorders.InstallDate

tbl_WO_Parts
tbl_WO_Parts.PartID
tbl_WO_Parts.SerialNumber

tbl_WO_ClaimAmt
tbl_WO_ClaimAmt.ClaimCode
tbl_WO_ClaimAmt.RequestType
tbl_WO_ClaimAmt.ClaimAmount

When I create the query using both tbl_WO_ClaimAmt and tbl_WO_Parts,
the records returned appear to have quadrupled for each customer.
Running the query with ONLY tbl_WO_Parts and the other tables(omitting
tbl_WO_Claim) returns the correct amount of records for each customer.
Running the query with ONLY tbl_WO_Claim and the other tables(omitting
tbl_WO_Parts) returns the correct amount of records for each customer.
As soon as I add both of these tables to the query is when the record
duplication occurs.

Here is the SQL, I hope it will be helpful:

SELECT DISTINCTROW tbl_WorkorderParts.PartID,
tbl_WorkorderParts.SerialNumber, tbl_Customers.[First Name],
tbl_Customers.[Last Name], tbl_Customers.[Home Phone],
tbl_MIGWorkorder.[Install Date], tbl_Employees.FirstName,
tbl_Employees.LastName, tbl_MIGWorkorder.AccountNum,
tbl_WorkOrderClaimAmt.ClaimCode, tbl_WorkOrderClaimAmt.RequestType,
tbl_WorkOrderClaimAmt.ClaimAmount
FROM (tbl_Employees INNER JOIN ((tbl_Customers INNER JOIN
tbl_MIGWorkorder ON tbl_Customers.CustomerID =
tbl_MIGWorkorder.CustomerID) LEFT JOIN tbl_WorkOrderClaimAmt ON
tbl_MIGWorkorder.WorkOrderID = tbl_WorkOrderClaimAmt.WorkOrderID) ON
tbl_Employees.EmployeeID = tbl_MIGWorkorder.EmployeerID) INNER JOIN
tbl_WorkorderParts ON tbl_MIGWorkorder.WorkOrderID =
tbl_WorkorderParts.WorkorderID;

I'm not sure if the order I've added the fields makes a difference
here, but this is how the client wants the data to appear. (The client
BTW is a close friend of mine so I hope you can understand why he
asked a newb like me to do this ;-)

Each workorder only has 1 CustomerID and 1 WorkorderID, but as you can
imagine many different parts and serial numbers and many different
claim codes and prices can be associated to 1 customer.
So we might have something like:

WorkOrderID
CustomerName
AccountNumber
PartID1
PartID2
PartID3
SerialNum1
SerialNum2
SerialNum3
ClaimCode1
ClaimCode2
ClaimCode3
ClaimAmount1
ClaimAmount2
ClaimAmount3

As noted earlier omitting either the tbl_Parts or tbl_ClaimAmt from
the query produces the correct results. But as soon as both
tables.fields are used the records quadruple. This is probably
something quite simple for you gurus out there, but as the subject
says, I'm an idiot ;-)

TIA to anyone who replies.

Best Regards,
Ross
 
A

Amy Blankenship

Did you hand write this query or did you let the query builder build it for
you? The reason I ask is that everything looks pretty normal to me until
the last parentheses, where you have another inner join expression just sort
of stuck onto the end of your nested joins.

If you're not using the query builder, I suggest you do so. If you are
using the query builder, it looks like something is not right in the way
you've set up the relationships between the queries.

HTH;

Amy

Ross said:
I don't think you can have left joins inside inner joins. If this is what
you need, create separate left join queries, then use another query to
join
them in an inner join.

HTH;

Amy

Thanks for your reply Amy. I'm not sure I need left joins or not, only
that the recordset is displaying 4x as many records as it should.
Following your advice I created 2 queries with tbl_MIGWOrkorder and
tbl_ClaimAmt created a left join, tbl_MIGWOrkorder and tbl_Parts and
created a left join. I then used those queries in a new query to try
and display the results I'm looking for. Unfortunately I must be doing
something wrong because the results are still the same. Here is the
SQL if it helps:

SELECT DISTINCTROW tbl_Customers.[First Name], tbl_Customers.[Last
Name], tbl_Customers.[Home Phone], qry_Parts_Left_Join.PartID,
qry_Parts_Left_Join.SerialNumber, tbl_MIGWorkorder.[Install Date],
tbl_Employees.FirstName, tbl_Employees.LastName,
tbl_MIGWorkorder.AccountNum, qry_ClaimAmt_Left_Join.ClaimCode,
qry_ClaimAmt_Left_Join.RequestType,
qry_ClaimAmt_Left_Join.ClaimAmount, qry_ClaimAmt_Left_Join.cxPaid
FROM ((tbl_Customers INNER JOIN (tbl_Employees INNER JOIN
tbl_MIGWorkorder ON tbl_Employees.EmployeeID =
tbl_MIGWorkorder.EmployeerID) ON tbl_Customers.CustomerID =
tbl_MIGWorkorder.CustomerID) INNER JOIN qry_ClaimAmt_Left_Join ON
tbl_MIGWorkorder.WorkOrderID = qry_ClaimAmt_Left_Join.WorkOrderID)
INNER JOIN qry_Parts_Left_Join ON tbl_MIGWorkorder.WorkOrderID =
qry_Parts_Left_Join.WorkorderID;


I'm not sure if I created the left-join queries correctly, perhaps it
would help if you saw the SQL for those:

SELECT tbl_WorkorderParts.PartID, tbl_WorkorderParts.SerialNumber,
tbl_MIGWorkorder.WorkOrderID
FROM tbl_MIGWorkorder LEFT JOIN tbl_WorkorderParts ON
tbl_MIGWorkorder.WorkOrderID = tbl_WorkorderParts.WorkorderID;

And:

SELECT tbl_WorkOrderClaimAmt.ClaimCode,
tbl_WorkOrderClaimAmt.RequestType, tbl_WorkOrderClaimAmt.ClaimAmount,
tbl_WorkOrderClaimAmt.cxPaid, tbl_MIGWorkorder.WorkOrderID
FROM tbl_MIGWorkorder LEFT JOIN tbl_WorkOrderClaimAmt ON
tbl_MIGWorkorder.WorkOrderID=tbl_WorkOrderClaimAmt.WorkOrderID;

I'm completely stuck, any help you could provide me would be greatly
appreciated.

Best Regards,
Ross



Ross said:
Hi,
Sorry for not being able to understand my problem fully. I'm hoping
someone can help. I am trying to create a recordset from a query to
display customer workorders, parts used, the employee who serviced the
account and amounts to be billed. The results are to be formatted as
per customer request and exported to an Excel spreadsheet.

Here are the tables and fields I am using to build this query:

tbl_Customers
tbl_Customers.FirstName
tbl_Customers.LastName
tbl_Customers.HomePhone

tbl_Employees
tbl_Employees.FirstName
tbl_Employees.LastName

tbl_Workorders
tbl_Workorders.WorkorderID <- primary key
tbl_Workorders.AccountNumber
tbl_Workorders.InstallDate

tbl_WO_Parts
tbl_WO_Parts.PartID
tbl_WO_Parts.SerialNumber

tbl_WO_ClaimAmt
tbl_WO_ClaimAmt.ClaimCode
tbl_WO_ClaimAmt.RequestType
tbl_WO_ClaimAmt.ClaimAmount

When I create the query using both tbl_WO_ClaimAmt and tbl_WO_Parts,
the records returned appear to have quadrupled for each customer.
Running the query with ONLY tbl_WO_Parts and the other tables(omitting
tbl_WO_Claim) returns the correct amount of records for each customer.
Running the query with ONLY tbl_WO_Claim and the other tables(omitting
tbl_WO_Parts) returns the correct amount of records for each customer.
As soon as I add both of these tables to the query is when the record
duplication occurs.

Here is the SQL, I hope it will be helpful:

SELECT DISTINCTROW tbl_WorkorderParts.PartID,
tbl_WorkorderParts.SerialNumber, tbl_Customers.[First Name],
tbl_Customers.[Last Name], tbl_Customers.[Home Phone],
tbl_MIGWorkorder.[Install Date], tbl_Employees.FirstName,
tbl_Employees.LastName, tbl_MIGWorkorder.AccountNum,
tbl_WorkOrderClaimAmt.ClaimCode, tbl_WorkOrderClaimAmt.RequestType,
tbl_WorkOrderClaimAmt.ClaimAmount
FROM (tbl_Employees INNER JOIN ((tbl_Customers INNER JOIN
tbl_MIGWorkorder ON tbl_Customers.CustomerID =
tbl_MIGWorkorder.CustomerID) LEFT JOIN tbl_WorkOrderClaimAmt ON
tbl_MIGWorkorder.WorkOrderID = tbl_WorkOrderClaimAmt.WorkOrderID) ON
tbl_Employees.EmployeeID = tbl_MIGWorkorder.EmployeerID) INNER JOIN
tbl_WorkorderParts ON tbl_MIGWorkorder.WorkOrderID =
tbl_WorkorderParts.WorkorderID;

I'm not sure if the order I've added the fields makes a difference
here, but this is how the client wants the data to appear. (The client
BTW is a close friend of mine so I hope you can understand why he
asked a newb like me to do this ;-)

Each workorder only has 1 CustomerID and 1 WorkorderID, but as you can
imagine many different parts and serial numbers and many different
claim codes and prices can be associated to 1 customer.
So we might have something like:

WorkOrderID
CustomerName
AccountNumber
PartID1
PartID2
PartID3
SerialNum1
SerialNum2
SerialNum3
ClaimCode1
ClaimCode2
ClaimCode3
ClaimAmount1
ClaimAmount2
ClaimAmount3

As noted earlier omitting either the tbl_Parts or tbl_ClaimAmt from
the query produces the correct results. But as soon as both
tables.fields are used the records quadruple. This is probably
something quite simple for you gurus out there, but as the subject
says, I'm an idiot ;-)

TIA to anyone who replies.

Best Regards,
Ross
 
R

Ross

On Thu, 9 Feb 2006 23:30:19 -0600, "Amy Blankenship"


Hi Amy, thanks again for your time.
Did you hand write this query or did you let the query builder build it for
you? The reason I ask is that everything looks pretty normal to me until
the last parentheses, where you have another inner join expression just sort
of stuck onto the end of your nested joins.

I used the query builder. Obviously not very well ;-)
If you're not using the query builder, I suggest you do so. If you are
using the query builder, it looks like something is not right in the way
you've set up the relationships between the queries.

I tried an experiment to see if I could just join the 2 queries that
appear to be producing the duplicate records.

SQL:

SELECT DISTINCTROW qry_Parts_Left_Join.PartID,
qry_Parts_Left_Join.SerialNumber, qry_ClaimAmt_Left_Join.ClaimCode,
qry_ClaimAmt_Left_Join.RequestType,
qry_ClaimAmt_Left_Join.ClaimAmount, qry_ClaimAmt_Left_Join.WorkOrderID
FROM qry_ClaimAmt_Left_Join INNER JOIN qry_Parts_Left_Join ON
qry_ClaimAmt_Left_Join.WorkOrderID = qry_Parts_Left_Join.WorkOrderID;


This still produces duplicate records. Both these tables are related
to static tables that contain only the Claim and Part information,
I've populated the fields from these tables (lookup fields?). Could
this be having an effect? Is there any other information I could post
that would be of benefit?
I managed to create a dataset and export it to Excel by running each
query separately, but this is a horrible kludge and really not what I
want to do in the long term.

Thanks again for your help.

Regards,
Ross
 
A

Amy Blankenship

Tell you what...if you want to send me you database zipped you can at amy at
magnoliamultimedia dot com.

-Amy
 
R

Ross

Tell you what...if you want to send me you database zipped you can at amy at
magnoliamultimedia dot com.

Amy, what an incredibly generous offer. Thank you very much.
You are a queen among women.

Sincerely,
M Ross

Zipped and sent.
 
J

John Vinson

Amy, what an incredibly generous offer. Thank you very much.
You are a queen among women.

Sincerely,
M Ross

Zipped and sent.

Let's just hope that your .sig was a coincidence... :-{)


John W. Vinson[MVP]
 
R

Ross

Let's just hope that your .sig was a coincidence... :-{)


Indeed ;-). Unfortunately, Amy ran into the same problems I've had
with the query. You wouldn't have any thoughts on this problem would
you?

Thanks,
Ross
 
A

Amy Blankenship

Now wait a second, here. The problem is that you have more than one record
on one side of the join that can match the other side of the join, which is
why you are getting a Cartesian set. You need to revise your database
design so as to provide a way to tell the database which half goes with
which other half. I already told you that, and you said you'd post to the
tablesdbdesign forum with the business requirements of your database so that
others could help you do that.

I wash my hands!
 
J

John Vinson

Indeed ;-). Unfortunately, Amy ran into the same problems I've had
with the query. You wouldn't have any thoughts on this problem would
you?

Sounds like Amy has correctly diagnosed the design flaw in your
database.

Fix the design flaw. Then your problem will go away.

John W. Vinson[MVP]
 
R

Ross

Now wait a second, here. The problem is that you have more than one record
on one side of the join that can match the other side of the join, which is
why you are getting a Cartesian set. You need to revise your database
design so as to provide a way to tell the database which half goes with
which other half. I already told you that, and you said you'd post to the
tablesdbdesign forum with the business requirements of your database so that
others could help you do that.

I wash my hands!

Thanks for all your help Amy.

Regards,
Ross
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top