Results 1 to 7 of 7
  1. #1
    coach32 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    47

    Inner join query not quite right

    I have two queries; the first is:
    [code]SELECT Max(tblWinnersOnlyAllAges.P1) AS MaxFor, tblWinnersOnlyAllAges.Team, tblWinnersOnlyAllAges.Age


    FROM tblWinnersOnlyAllAges
    GROUP BY tblWinnersOnlyAllAges.Team, tblWinnersOnlyAllAges.Age
    ORDER BY tblWinnersOnlyAllAges.Team, tblWinnersOnlyAllAges.Age;[code]
    The results from this query are exactly what I want to start with.
    eg: Berwick U10 162
    Berwick U11 175
    Berwick U12 180 etc. This is done for all Teams. After this query I need to show what is on the whole row of each of the Maximum records, so I ran the following query:
    [code]SELECT tblWinnersOnlyAllAges.*, tblWinnersOnlyAllAges.Team, tblWinnersOnlyAllAges.Age, tblWinnersOnlyAllAges.P1
    FROM tblWinnersOnlyAllAges INNER JOIN qryHSFAll ON tblWinnersOnlyAllAges.Team = qryHSFAll.Team
    WHERE (((tblWinnersOnlyAllAges.P1)=[qryHSFAll]![MaxFor]));[code]
    This almost works, except it show an odd record every now and then and I can't understand why. eg: Berwick 26 10 162 U10 1988 is the Maximum value for that Team in that Age but the results may also show Berwick 22 12 144 U10 1991. Could anyone please shed some understanding on what I am doing wrong with my second query. Thank-you for taking the time to look at this long winded post.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    End code tag should be /code.

    I would have to examine source data and test. If you want to provide, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    coach32 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    47

    Inner join query not quite right

    Thank you June7 for taking a look. I have attached an abbreviated version. When you run the second query (qryHSFAllA), sort the 'Team' names, you will see that, for example Beaconsfield have two lines for Under 13s with different values. I only wanted the Maximum value for each age which shows in the first query (qryHSFAll).
    Attached Files Attached Files

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Till June's back,

    Try running below query & see what happens :
    Code:
    SELECT 
        qryHSFAll.Team, 
        qryHSFAll.Age, 
        qryHSFAll.MaxFor, 
        tblWinnersOnlyAllAges.*
    FROM 
        qryHSFAll 
        INNER JOIN 
        tblWinnersOnlyAllAges 
        ON 
        (qryHSFAll.Team = tblWinnersOnlyAllAges.Team) 
        AND 
        (qryHSFAll.Age = tblWinnersOnlyAllAges.Age) 
        AND 
        (qryHSFAll.MaxFor = tblWinnersOnlyAllAges.P1)
    ORDER BY 
        qryHSFAll.Team, qryHSFAll.Age, qryHSFAll.MaxFor;
    This query will give you 129 records versus 125 records of qryHSFAll.
    If you now look at your data in table tblWinnersOnlyAllAges,
    you will find
    1) Beaconsfield U14 has 2 records with max value 195.
    2) Berwick U13 has 2 records with max value 237.
    3) Berwick Springs/Beaconsfield U14 has 2 records with max value 91.
    4) Dandenong Saints (St.Mary's Church) U15 has 2 records with max value 193.

    This, I believe is the first thing that needs to be looked in to ( either the logic of the grouping in qryHSFAll or the data in tblWinnersOnlyAllAges ).

    Thanks

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    When I open qryHSFAllA I get an input parameter prompt for Query1.tblWinnersOnlyAllAges.Team. Very odd because nothing in the sql statement references Query1. I just OK past the prompt and the query opens with 181 records. I remove the Team and Age fields from the query grid because they are already captured by the field wildcard (*). Now the prompt no longer pops and I still get the 181 records.

    However, there are only 2 Beaconsfield records, for U10 and U13. Not getting the issue you describe with that query.

    recyan has exposed what I suspected but had not yet tracked down - that more than one record matches to the Max value.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    coach32 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    47
    Thank-you to recyan and June7. I ran the query and that's the results I want. I should say that there will be the odd time that a Team does have a multiple Max value.

  7. #7
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Glad you got things working.

    Thanks

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

Similar Threads

  1. Join Query?
    By KWarzala in forum Forms
    Replies: 5
    Last Post: 07-29-2014, 02:44 PM
  2. Join Query
    By hithere in forum Queries
    Replies: 4
    Last Post: 02-17-2012, 06:18 AM
  3. inner join query with three tables.
    By fabiobarreto10 in forum Queries
    Replies: 2
    Last Post: 01-30-2012, 07:34 PM
  4. inner join in query
    By Hrcko in forum Access
    Replies: 1
    Last Post: 02-01-2010, 05:54 PM
  5. Stuck on Join Query
    By Pimped in forum Queries
    Replies: 1
    Last Post: 10-26-2009, 10:54 AM

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