title: Looping over a tabular expression and run subquery for each row in KUSTO
body: <p>I have 2 tables (Tab1 , Tab2) with no common field, I would like to run a query on Tab2 for each row in Tab1 and Where condition in subquery should use column value from outer query.</p>
  <pre><code>Pseudo code 
  
  tab1
  | project timestamp, duration
  
  tab2
  | project event_time_t, data
  
  pseudo code/ desired query
  
  tab1 join tab2
  | where event_time_t between (tab1.timestamp .. datetime_add('millisecond',toint(tab1.duration),tab1.timestamp))
  </code></pre>
  <p>I have checked below options but couldn't got it working</p>
  <ol>
  <li>MV-Apply : couldn't got it working with tabular expression</li>
  <li>User defined function : have limitation with changing row context data</li>
  <li>repeat : works only with scalar</li>
  </ol>
  <p><strong>UPDATE:</strong></p>
  <p>Adding more clarity to my question.</p>
  <p>I want to find all rows from T2 which lies between T1.timestamp and add_datetime(T1.timestamp + duration_millisecond)</p>
  <p>I did tried the cross join approach and got desired result but its to costly as my T2 table is huge. Can i do this programmatically some how as we do in T-SQL corelated subquery where a subquery gets executed for each row in T1 and change the between clause dynamically with reference to outer query?</p>
  <pre><code>let T1 = datatable(OperationID:sring,timestamp:datetime, duration_millisecond:int)
  [
      1, datetime(2021-02-15T10:56:28.768), 22 ,
      2, datetime(2021-02-15T11:28:28.165), 17 ,
      3, datetime(2021-02-15T12:29:48.954), 90 ,
      4, datetime(2021-02-15T13:30:09.786), 2 ,
      5, datetime(2021-02-15T14:30:22.333), 6 ,
  ];
  let T2 = datatable(event_time_t:datetime, data:string)
  [
      datetime(2021-02-15T10:56:28.775), &quot;Some string&quot;, 
      datetime(2021-02-15T10:56:28.788), &quot;Another string&quot;, 
      datetime(2021-02-15T11:28:28.167), &quot;Yet another string&quot;, 
      datetime(2021-02-15T12:29:48.954), &quot;Last string1&quot;,
      datetime(2021-02-15T12:29:48.999), &quot;Last string2&quot;,
      datetime(2021-02-15T12:29:49.023), &quot;Last string3&quot;,
      datetime(2021-02-15T12:29:49.025), &quot;Last string4&quot;,
      datetime(2021-02-15T13:30:09.787), &quot;Last string5&quot;,
      datetime(2021-02-15T14:30:22.335), &quot;Last string6&quot;,
      datetime(2021-02-15T14:30:22.337), &quot;Last string7&quot;,
  ];
  T1
  | extend temp=1
  | join kind=fullouter (
      T2
      | extend temp=1
  ) on temp
  | project-away temp, temp1
  | where event_time_t between (timestamp .. datetime_add('millisecond',duration_millisecond,timestamp))
  </code></pre>
  <p>Expected Result:</p>
  <pre><code>Result = datatable(OperationID:sring,timestamp:datetime, duration_millisecond:int, event_time_t:datetime, data:string)
  [
      1, datetime(2021-02-15T10:56:28.768), 22 ,datetime(2021-02-15T10:56:28.775), &quot;Some string&quot;,
      1, datetime(2021-02-15T10:56:28.768), 22 ,datetime(2021-02-15T10:56:28.788), &quot;Another string&quot;,
      2, datetime(2021-02-15T11:28:28.165), 17 ,datetime(2021-02-15T11:28:28.167), &quot;Yet another string&quot;,
      3, datetime(2021-02-15T12:29:48.954), 90 ,datetime(2021-02-15T12:29:48.954), &quot;Last string1&quot;,
      3, datetime(2021-02-15T12:29:48.954), 90 ,datetime(2021-02-15T12:29:48.999), &quot;Last string2&quot;,
      3, datetime(2021-02-15T12:29:48.954), 90 ,datetime(2021-02-15T12:29:49.023), &quot;Last string3&quot;,
      3, datetime(2021-02-15T12:29:48.954), 90 ,datetime(2021-02-15T12:29:49.025), &quot;Last string4&quot;,
      4, datetime(2021-02-15T13:30:09.786), 2 ,datetime(2021-02-15T13:30:09.787), &quot;Last string5&quot;,
      5, datetime(2021-02-15T14:30:22.333), 6 ,datetime(2021-02-15T14:30:22.335), &quot;Last string6&quot;,
      5, datetime(2021-02-15T14:30:22.333), 6 ,datetime(2021-02-15T14:30:22.337), &quot;Last string7&quot;, 
  ]
  </code></pre>