For Microsoft Defender and Microsoft Sentinel
KQL cheat sheet
The KQL you use most in Microsoft Defender advanced hunting and Microsoft Sentinel, on one page. The examples use Defender tables. In Sentinel, swap Timestamp for TimeGenerated.
Checked against Microsoft’s KQL documentation in November 2026.
Filter rows
| To do this | Write this |
|---|---|
| Start from a table | |
Last 24 hoursSentinel tables use TimeGenerated. | |
| Between two times | |
| Exact match, case matters | |
| Exact match, ignore case | |
| Not equal, ignore case | |
One of several, ignore casein without the ~ is case-sensitive. | |
| Contains a whole wordFastest text search. Ignores case. | |
| Contains any of several words | |
Contains text anywhere, even mid-wordSlower than has. Ignores case. | |
| Starts with | |
| Matches a regexCase-sensitive. | |
| Has a value | |
Choose columns
| To do this | Write this |
|---|---|
| Keep only these columns | |
| Drop a column | |
| Rename a column | |
| Add a calculated column | |
Count, sort and group
| To do this | Write this |
|---|---|
| Count all rows | |
Count by a columnThe new column is called count_. | |
| Count, with your own column name | |
Count distinct valuesdcount() is an estimate. It can be slightly off on large data. | |
| Count per hour | |
| First and last seen | |
| Latest row for each device | |
| List the values in each group | |
| Unique combinations | |
SortWith no asc or desc, sort is descending. | |
| Top 10 by a column | |
Any 10 rows, to look at the dataNo order. Use top when order matters. | |
Combine tables
| To do this | Write this |
|---|---|
Join another tableAlways set kind. The default drops duplicate keys on the left. | |
| Join on columns with different names | |
| Keep rows with no match on the right | |
| Stack two tables | |
| Reuse a list of values | |
Read messy fields
| To do this | Write this |
|---|---|
| Read a JSON column | |
| Take one value out of JSON | |
Pull text out with a regex0 returns the whole match, 1 the first group. | |
| One row per array item | |
| Split text | |
Watch out for
==is case-sensitive and=~isn’t. Outlook.EXE and outlook.exe are different to==.hasmatches whole words, sohas "Explorer"won’t findKustoExplorerQueryRun. Usecontainsfor part of a word.- A
joinwith nokindisinnerunique, which keeps only one left row per key. Writekind=innerwhen you want every match. takereturns any rows, in no order. Usetoporsortwhen order matters.- Advanced hunting covers up to 30 days of Defender data, and all times are in UTC.
- Table, column and function names are case-sensitive.
deviceprocesseventswon’t work.
Official docs and cheat sheets
Microsoft publishes its own quick reference and two cheat sheets for people coming from SQL and Splunk.
- KQL quick referenceMicrosoft’s one-page list of KQL operators and functions.(opens in a new tab)
- SQL to KQL cheat sheetCommon SQL queries next to their KQL versions.(opens in a new tab)
- Splunk to KQL mapSplunk SPL commands and functions next to their KQL versions.(opens in a new tab)
- String operatorsEvery text operator, and which ones ignore case.(opens in a new tab)
- Advanced hunting overviewHow hunting works in Microsoft Defender XDR, with its limits.(opens in a new tab)
- Advanced hunting best practicesMicrosoft’s advice for faster, cheaper hunting queries.(opens in a new tab)
Keep going
- Practise and learn KQLTicket-style exercises on realistic lab data.
- KQL vs SPLMicrosoft Sentinel and Defender vs Splunk, side by side.
- Sentinel vs Defender tablesWhich Microsoft tables hold what, side by side.
- All cheat sheetsEvery language on one page.
- Elastic KQL and ES|QL cheat sheetFor Elastic Security and Kibana
- Sophos SQL cheat sheetFor Sophos Central Live Discover and Data Lake
Practise these in real exercises
A cheat sheet tells you the syntax. SOC Fluent gives you exercises to solve with it, on realistic lab data, and shows you what your query missed. Join the waitlist and we’ll email you once, on launch day.
Free to join. Students get 50% off at launch.