• AccessXP Query Question (AccessXp)

    Author
    Topic
    #396131

    Hi Rich…

    All you have to do is create a second query…. Keep the totals query as is (with just the Min and Max of Cost)…
    Then create a second query that joins the Table to the totals query on the Cost field… The inner join will return only the records where those amounts match (ie the Min and Max Cost records)… In this query, select the Description field from the table and you should get the results you are looking for…

    HTH

    Viewing 2 reply threads
    Author
    Replies
    • #739985

      We’re trying to design a Query that returns the Highest Costing Item, and the Lowest Costing Item. Our table includes a field name of Description, and another field name of Cost.
      We ran the Query successfully using totals to find at the same time the Max and the Min for the “Cost” field. But we want to know the Description of the Highest and the Lowest! When we include the field “Description”, the Query returns all the records, not simpply max and min.

      Does anybody know how we could show the “Description” and the Max and Min?

      Thanks,
      Rich
      see http://www.mrwteaches.net/d221%5B/url%5D

      (URL corrected and made clickable by HansV – see Help 19)

    • #739986

      We’re trying to design a Query that returns the Highest Costing Item, and the Lowest Costing Item. Our table includes a field name of Description, and another field name of Cost.
      We ran the Query successfully using totals to find at the same time the Max and the Min for the “Cost” field. But we want to know the Description of the Highest and the Lowest! When we include the field “Description”, the Query returns all the records, not simpply max and min.

      Does anybody know how we could show the “Description” and the Max and Min?

      Thanks,
      Rich
      see http://www.mrwteaches.net/d221%5B/url%5D

      (URL corrected and made clickable by HansV – see Help 19)

    • #741294

      Hi Trudi,

      Thank you so much for your quick reply!

      I tried your suggestion, but I must not be doing something correct. Maybe I’m not as familiar with inner joins. I still can get it to work the way we envisioned! I get no results. Do I run the new query to see all the info we’re after?

      Any suggestions?

      Thanks a bunch,
      G’Day,
      Rich

      • #741319

        Let’s say that you have a table tblCosts with fields ID (AutoNymber), Description (Text) and Cost (Currency).

        1. Create a query qryMinMax that returns the lowest and highest costs:

        SELECT Min([Cost]) AS MinCost, Max([Cost]) AS MaxCost FROM tblCosts

        2. Create a query based in qryMinMax and on two instances of tblCosts. Join one instance to qryMinMax on Cost vs MinCost, and the other instance on Cost vs MaxCost. Return the Description field from each:

        SELECT tblCosts.Description AS [Least Expensive], qryMinMax.MinCost, tblCosts_1.Description AS [Most expensive], qryMinMax.MaxCost
        FROM (qryMinMax INNER JOIN tblCosts ON qryMinMax.MinCost = tblCosts.Cost) INNER JOIN tblCosts AS tblCosts_1 ON qryMinMax.MaxCost = tblCosts_1.Cost
        GROUP BY tblCosts.Description, qryMinMax.MinCost, tblCosts_1.Description, qryMinMax.MaxCost;

        See screenshot.

      • #741320

        Let’s say that you have a table tblCosts with fields ID (AutoNymber), Description (Text) and Cost (Currency).

        1. Create a query qryMinMax that returns the lowest and highest costs:

        SELECT Min([Cost]) AS MinCost, Max([Cost]) AS MaxCost FROM tblCosts

        2. Create a query based in qryMinMax and on two instances of tblCosts. Join one instance to qryMinMax on Cost vs MinCost, and the other instance on Cost vs MaxCost. Return the Description field from each:

        SELECT tblCosts.Description AS [Least Expensive], qryMinMax.MinCost, tblCosts_1.Description AS [Most expensive], qryMinMax.MaxCost
        FROM (qryMinMax INNER JOIN tblCosts ON qryMinMax.MinCost = tblCosts.Cost) INNER JOIN tblCosts AS tblCosts_1 ON qryMinMax.MaxCost = tblCosts_1.Cost
        GROUP BY tblCosts.Description, qryMinMax.MinCost, tblCosts_1.Description, qryMinMax.MaxCost;

        See screenshot.

    Viewing 2 reply threads
    Reply To: AccessXP Query Question (AccessXp)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: