If you have a one-to-one correspondence between rows in sales line table and sales header table, then what you need is something like this:SELECT [Posting Date], itemFROM( SELECT Salesheader.[Posting Date], Salesline.[No_] AS item, ROW_NUMBER() OVER (PARTITION BY Salesheader ORDER BY [Posting Date] DESC) AS RN FROM [TSG GROUP$Sales Header] AS Salesheader INNER JOIN [TSG GROUP$Sales Line] AS Salesline ON Salesheader.[No_] = Salesline.[Document No_])s;
Usually a sales header table would have one record and sales line table would have one or more records for each row in the sales header table. In your case that does not seem to be the case.