query table for latest timestamp

Occasional Visitor
let t =my_table
| summarize max(timestamp);
my_table
| where timestamp == t;

why doesn't this work?

I get

  'where' operator: Failed to resolve column or scalar expression named 't'

1 Reply

@Hanan_Shteingart 

Hello Hanan, I think it works with a little change.

 

By default Kusto returns a set of data -  just like any other database. But you don't want to return a set, you are returning a single value like: " | where timestamp = datetime(2022-12-24)". This is why you need to use toscalar.

 

let  mytable =

datatable(timestamp:datetime) [

    datetime(1910-06-11),

    datetime(1930-01-01),

    datetime(1953-01-01),

    datetime(1997-06-25),

];

let t = mytable |  summarize max(timestamp);

mytable

| where timestamp == toscalar(t);

 

 

Or if you are NOT searching for a single value but the whole set, you would use the IN operator, not ==

mytable

| where timestamp  in (mytable);