Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using both 'distinct' and 'project'

In Azure Data Explorer, I am trying to use both the 'project' and 'distinct' keywords. The table records have 3 fields I want to use the 'project' on:

  1. CowName
  2. CowType
  3. CowNum
  4. CowLabel

But there are many other fields in the table such as Date, Measurement, etc, that I do not want to return.

Cows
| project CowName, CowType, CowNum, CowLabel

However, I want to avoid duplicate records of CowName and CowNum, so I included

Cows
| project CowName, CowType, CowNum, CowLabel
| distinct CowName, CowNum

But when I do this, the only columns that are returned are CowName and CowNum. I am now missing CowType and CowLabel entirely.

Is there a way to use both 'project' and 'distinct' without them interfering with each other? Is there a different approach I should take?

like image 652
Adam Avatar asked Nov 21 '25 23:11

Adam


1 Answers

You can do:

Cows
| distinct CowName, CowType, CowNum

or, if you don't want to have distinct values of CowType - and just have any value of it:

Cows
| summarize any(CowType) by CowName, CowNum

References:
Summarize operator: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/summarizeoperator
Distinct operator:https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/distinctoperator
any() aggregation function: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/any-aggfunction

like image 87
Alexander Sloutsky Avatar answered Nov 24 '25 20:11

Alexander Sloutsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!