title: Get latest record per Item
body: <p>I need to create a list of Item Masters which will show the latest Invoice and Sales Order record. The code I have created shows ALL the records, I need the one with the newest DocDate....</p>
  
  <p>Your assistance is greatly appreciated!</p>
  
  <pre><code>        SELECT DISTINCT
          T0.[ItemCode], 
          T1.[ObjType], 
          T1.[DocNum], 
          MAX(T1.[DocDate])  AS 'LastActivity'
      FROM INV1 T0  INNER JOIN OINV T1 ON T0.[DocEntry] = T1.[DocEntry]
  
  
      GROUP BY 
          T0.[ItemCode], 
          T1.[ObjType], 
          T1.[DocNum]
  
  UNION ALL
  
      SELECT DISTINCT
          T0.[ItemCode], 
          T1.[ObjType], 
          T1.[DocNum], 
          MAX(T1.[DocDate])  AS 'LastActivity'
      FROM RDR1 T0  INNER JOIN ORDR T1 ON T0.[DocEntry] = T1.[DocEntry]
  
  
      GROUP BY 
          T0.[ItemCode], 
          T1.[ObjType], 
          T1.[DocNum]
  </code></pre>