title: Article stock transaction table query Max Date gives multiple results on same timestamp, only need the last
body: <p>I've got an Article Stock transaction table, I only need the columns: Article, Date and Stock.</p>
  <p>On the Same day, even on the same timestamp the table gives me multiple results for the same article, I only need the article with the latest date. It seems that the last in row is the article with the most recent Stock value. Bud how can I write this in a query that it only shows me the latest Date? (Blue row in Screenshot)</p>
  <p>In my example I filtered it on only one article.</p>
  <pre><code> SELECT artikel as Article, max(datum) as `Date`, bestand as 
   Stock  FROM data.HB001ARTIKELBESTANDSBEWEGUNG
   where datum &gt; &quot;2021-08-11 00:00:00&quot; and datum &lt; &quot;2021-08-13 
  00:00:00&quot; and lager = 1 and artikel = '5201114970'
  group by artikel, bestand, datum
  order by artikel;
  
   
  </code></pre>
  <p><a href="https://i.stack.imgur.com/b32nk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b32nk.png" alt="Result Query" /></a></p>
  <p>With kind regards,</p>
  <p>Björn</p>
  <p>I added the extra row with the auto increment, so now I get for every article with the latest date the highest row number. How can I filter now that i only get one result per article?</p>
  <pre><code>SELECT Article, max(CountDate), Stock, Nr  FROM data.STOCKCOUNT
  where CountDate &gt; &quot;2021-08-11 00:00:00&quot;  and CountDate &lt; &quot;2021- 
  08-13 00:00:00&quot; and Article IN ('5201114970', '1361001580')
  group by Article, Stock, CountDate, Nr
  order by Nr, CountDate desc, Article;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/77ovG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/77ovG.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/Xwmsv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xwmsv.png" alt="enter image description here" /></a></p>
  <p>I added the extra row with the auto increment, so now I get for every article with the latest date the highest row number. How can I filter now that i only get one result per article filtered on the highest row number per article?</p>
  <pre><code>SELECT artikel as Article, max(datum) as Date, bestand as Stock, 
  ROW_NUMBER() OVER(ORDER BY datum asc) as Nr  FROM 
  data.HB001ARTIKELBESTANDSBEWEGUNG b where datum &gt; &quot;2021-08-11 
  00:00:00&quot; and datum &lt; &quot;2021-08-13 00:00:00&quot; and lager = 1 and 
  artikel in ('5201114970', '1361001580') group by artikel, 
  bestand, datum order by datum desc, artikel
  </code></pre>
  <p><a href="https://i.stack.imgur.com/uFnyu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uFnyu.png" alt="enter image description here" /></a></p>