Results 1 to 6 of 6
  1. #1
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176

    Running a query to count, is multiplying by number of other criteria?

    I have 3 fields (ProjectCode,TradeCode, QuestionID)

    Each project has various trades in it. Each question can come from any trade.

    I thought I would run a simple count query, grouping by the other 2:

    SELECT dbo_Bid.ProjectCode, dbo_Bid.TradeCode, Count(dbo_BiddersQuestions.QuestionId) AS CountOfQuestionId


    FROM dbo_Bid INNER JOIN dbo_BiddersQuestions ON (dbo_Bid.TradeCode = dbo_BiddersQuestions.TradeCode) AND (dbo_Bid.TradeCode = dbo_BiddersQuestions.TradeCode) AND (dbo_Bid.ProjectCode = dbo_BiddersQuestions.ProjectCode)
    GROUP BY dbo_Bid.ProjectCode, dbo_Bid.TradeCode;

    but for some reason the count is multiplied but the number of trades per project.

    ex: A project has trades A B and C. A asked 3 questions B asked 2 and C asked 5

    what I get is that A asked 9, B asked 6, and C asked 15

    If ther is only one trade it gives the the right answer, if 2 trades then it doubles it.

    Can this have something to do with the way I set up the relationships?

    Thanks!

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    but for some reason the count is multiplied but the number of trades per project.
    ...
    Can this have something to do with the way I set up the relationships?
    Quite possibly. It sounds like you may have some many-to-many relationships working here.

    It would probably being very helpful if you could post some small data samples of each table, and your expected results from that data.
    Many times a visual representation makes it quite clearer for us to see what you are working with.

  3. #3
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    So I took some pictures of what I have already

    Here is the data:
    Click image for larger version. 

Name:	Capture1.PNG 
Views:	1 
Size:	20.4 KB 
ID:	12694
    Here is what I get:
    Click image for larger version. 

Name:	Capture2.PNG 
Views:	1 
Size:	5.1 KB 
ID:	12695
    What I want to get is

    40413 P 3
    40413 H 1
    40413 C 18
    (the order doesn't matter)

    Here are the relationships : (I only used the 2 tables)
    Click image for larger version. 

Name:	Capture3.PNG 
Views:	1 
Size:	30.9 KB 
ID:	12696

    Thanks

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    What is the first image of? One of your tables? Or an intermediate query?
    It would be helpful to see images of the two original tables you are joining.

  5. #5
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    So actually, taking a closer look at what I was trying to do, I really only need one table, which makes everything much simple and now it works. And yes the first image was a temporary query I had run to get the data I wanted.
    Sorry, and Thanks!

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Glad you got it working.
    Sometimes, it helps just to talk it out.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Running Sum by Date criteria in a query
    By inno in forum Access
    Replies: 6
    Last Post: 11-08-2012, 12:33 AM
  2. Running page count tied to volume number
    By bmj121 in forum Programming
    Replies: 5
    Last Post: 04-27-2012, 11:24 AM
  3. Running Query on only 1 row of table.. Criteria?
    By JMac in forum Database Design
    Replies: 5
    Last Post: 04-16-2012, 11:27 PM
  4. Replies: 6
    Last Post: 07-25-2011, 01:54 PM
  5. Running Count Query
    By monkey2003 in forum Queries
    Replies: 0
    Last Post: 09-21-2009, 12:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums