title: Outer apply in kusto/ Azure AppInsights
body: <p>I am new to azure appinsight and kusto, I am trying to write a kusto query that will group items in a table and look for the latest record by time.</p>
  
  <p>This is what i tried so far,</p>
  
  <p>Sample Table:</p>
  
  <pre><code>let Temptable=datatable(RunId:string,Module:string,AppName:string,timestamp:datetime) [
    "1", "start",   "App1", '2020-02-27T04:30:01.6062658Z',
    "1", "end",   "App1", '2020-02-27T04:31:01.6062658Z',
    "2", "start",   "App1", '2020-02-27T04:00:01.6062658Z',
    "2", "end",   "App1", '2020-02-27T04:01:01.6062658Z',
    "3", "start",   "App1", '2020-02-27T03:30:01.6062658Z',
    "3", "end",   "App1", '2020-02-27T03:31:01.6062658Z',
    "4", "start",   "App1", '2020-02-27T03:00:01.6062658Z',
    "4", "end",   "App1", '2020-02-27T03:01:01.6062658Z',
    "5", "start",   "App1", '2020-02-27T02:30:01.6062658Z',
    "5", "end",   "App1", '2020-02-27T02:31:01.6062658Z',
    "6", "start",   "App2", '2020-02-27T04:00:01.6062658Z',
    "6", "end",   "App2", '2020-02-27T04:01:01.6062658Z',
    "7", "start",   "App2", '2020-02-27T03:00:01.6062658Z',
    "7", "end",   "App2", '2020-02-27T03:01:01.6062658Z',
    "8", "start",   "App2", '2020-02-27T02:00:01.6062658Z',
    "8", "end",   "App2", '2020-02-27T02:01:01.6062658Z',
    "9", "start",   "App2", '2020-02-27T01:00:01.6062658Z',
    "9", "end",   "App2", '2020-02-27T01:01:01.6062658Z',
    "10", "start",   "App2", '2020-02-27T00:30:01.6062658Z',
    "10", "end",   "App2", '2020-02-27T00:32:01.6062658Z'
  ];
  </code></pre>
  
  <p>I am running the below query,</p>
  
  <pre><code>let FactTable = Temptable
  | where Module == "start"
  | summarize by AppName
  | project AppName;
  FactTable
  | lookup kind = inner (Temptable | partition by AppName( summarize Maxtime = max(timestamp) by AppName | top 1 by Maxtime desc nulls last )) on AppName;
  </code></pre>
  
  <p>My output: </p>
  
  <p><a href="https://i.stack.imgur.com/P3yKO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P3yKO.png" alt="enter image description here"></a></p>
  
  <p>I need to retrieve all the columns for the latest record.</p>
  
  <p>Below is the query in sql, which will retrieve top 1 record for the particular AppName.</p>
  
  <pre><code>select cs.* 
      from (select AppName from #TempTable where Module = 'start' group by AppName) a
      outer apply (select top 1 * from #TempTable b where b.AppName = a.AppName order by [TimeStamp] desc) cs
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/QlanJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QlanJ.png" alt="enter image description here"></a></p>
  
  <p>How to achieve this in Kusto Query.</p>
  
  <p>Is there anyway to write query in kusto with outer column can be accessible in the subquery,or any other better approach?</p>