Last Function in Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Coolboy55
    New Member
    • Jul 2007
    • 67

    #1

    Last Function in Query

    I have a subquery where I am sorting first by ProductNumber and then by DateStamp.

    I want to find the last quantity of each product on a given date (the quantity changes throughout the day). My query currently groups by ProductNumber, looks for Max DateStamp, and Last Quantity. But it is not working properly. The Quantity never seems to be the actual last quantity, but something in the middle somewhere, even though I can see that the subquery is sorting properly, and it is correctly finding Max of DateStamp.

    Is there some way to pull the Quantity from the same record as the Max DateStamp is read from?

    Thanks!
  • Coolboy55
    New Member
    • Jul 2007
    • 67

    #2
    Nevermind, I found the problem. It turns out that if I use WHERE instead of GROUP BY and HAVING in the subquery, the results in the query are screwed up.

    Comment

    • Lysander
      Recognized Expert Contributor
      • Apr 2007
      • 344

      #3
      Hi Coolboy,

      Edited cause I dont have a delete option
      Last edited by Lysander; Dec 6 '10, 05:00 PM. Reason: User supplied answer as I typed suggestion

      Comment

      Working...