QRadar AQL Query Examples: 8 Ready-to-Use Queries for SOC Analysts

AQL (Ariel Query Language) is the SQL-like language used to query event and flow data in IBM QRadar. Grouping, counting, comparing time ranges and querying custom properties, things you can’t easily do with the Log Activity and Network Activity filters, take only a few lines in AQL. This guide collects the AQL queries SOC analysts use most often in day-to-day work, with explanations so you can adapt them to your own environment.
Where Do You Run AQL Queries?
- Log Activity: choose Advanced Search next to the search bar and type your query.
- Network Activity: the same way, using Advanced Search against the
flowstable. - API: run queries through the
/api/ariel/searchesendpoint and feed the results into automation tools. - Rules and reports: saved searches can be reused in dashboards and reports.
Basic AQL Syntax
SELECT <fields>
FROM events -- or flows
WHERE <conditions>
GROUP BY <field>
ORDER BY <field> DESC
LIMIT 100
LAST 24 HOURS -- or START '...' STOP '...'The time clause goes at the end of the query. You can use relative ranges such as LAST 15 MINUTES, LAST 2 HOURS or LAST 7 DAYS, or absolute ranges like START '2026-11-01 00:00' STOP '2026-11-02 00:00'. A wider time range than you need is the single biggest cause of slow queries.
Core Functions for Readable Results
QRadar stores many fields as numeric IDs. These functions turn them into something humans can read:
| Function | Returns |
|---|---|
LOGSOURCENAME(logsourceid) | Log source name |
LOGSOURCETYPENAME(devicetype) | Log source type (e.g. Microsoft Windows Security Event Log) |
QIDNAME(qid) | Event name |
CATEGORYNAME(category) | Low-level category name |
DATEFORMAT(starttime, 'yyyy-MM-dd HH:mm:ss') | Human-readable timestamp |
UTF8(payload) | Raw event payload as text |
INCIDR('10.0.0.0/8', sourceip) | Whether an IP is inside a given network |
1. Top Log Sources by Event Count (Last 24 Hours)
SELECT LOGSOURCENAME(logsourceid) AS "Log Source",
COUNT(*) AS "Event Count"
FROM events
GROUP BY logsourceid
ORDER BY "Event Count" DESC
LIMIT 20
LAST 24 HOURSThis is the first query to run when your EPS license is getting close to its limit or a source suddenly becomes noisy.
2. Failed Logons for a Specific User
SELECT DATEFORMAT(starttime, 'yyyy-MM-dd HH:mm:ss') AS "Time",
sourceip, destinationip, username,
QIDNAME(qid) AS "Event"
FROM events
WHERE username = 'example.user'
AND CATEGORYNAME(category) ILIKE '%fail%'
ORDER BY starttime DESC
LAST 7 DAYSILIKE performs case-insensitive matching. Category names depend on the DSMs in your environment, so check the actual category names first.
3. Brute Force Suspicion: Failed Logons per Source IP
SELECT sourceip,
UNIQUECOUNT(username) AS "Distinct Users",
COUNT(*) AS "Attempts"
FROM events
WHERE CATEGORYNAME(category) ILIKE '%authentication failed%'
GROUP BY sourceip
HAVING "Attempts" > 50
ORDER BY "Attempts" DESC
LAST 1 HOURSMany different usernames tried from a single IP is the classic signature of password spraying. Tune the threshold (50) to your environment’s normal behavior.
4. Internal Hosts Connecting to the Most External Destinations
SELECT sourceip,
COUNT(*) AS "Connections",
UNIQUECOUNT(destinationip) AS "Distinct Destinations"
FROM flows
WHERE INCIDR('10.0.0.0/8', sourceip)
AND NOT INCIDR('10.0.0.0/8', destinationip)
GROUP BY sourceip
ORDER BY "Distinct Destinations" DESC
LIMIT 25
LAST 6 HOURSA workstation talking to an unusually large number of external destinations can indicate scanning, malware C2 traffic or a misconfiguration. Replace the internal ranges with your own address plan.
5. High Outbound Volume (Possible Data Exfiltration)
SELECT sourceip, destinationip,
SUM(sourcebytes) / 1048576 AS "MB Sent"
FROM flows
WHERE NOT INCIDR('10.0.0.0/8', destinationip)
GROUP BY sourceip, destinationip
HAVING "MB Sent" > 500
ORDER BY "MB Sent" DESC
LAST 24 HOURSBackup servers and cloud sync services will naturally show up here. Keeping them in a reference set and excluding it from the query gives you a much cleaner result.
6. Text Search Inside Raw Payloads
SELECT DATEFORMAT(starttime, 'yyyy-MM-dd HH:mm:ss') AS "Time",
LOGSOURCENAME(logsourceid) AS "Source",
UTF8(payload) AS "Raw Event"
FROM events
WHERE UTF8(payload) ILIKE '%powershell -enc%'
LAST 2 HOURSPayload searches are expensive because every record has to be scanned. Keep the time range narrow and filter by log source first where possible. For values you search often, defining a custom property is far more efficient.
7. Unknown (Unparsed) Events
SELECT LOGSOURCENAME(logsourceid) AS "Source",
COUNT(*) AS "Count"
FROM events
WHERE QIDNAME(qid) ILIKE '%unknown%'
GROUP BY logsourceid
ORDER BY "Count" DESC
LAST 24 HOURSA source producing lots of unknown events usually means the wrong DSM was selected or the log format changed. These events can’t be evaluated properly by your rules.
8. Hourly Event Trend for a Source
SELECT DATEFORMAT(starttime, 'yyyy-MM-dd HH') AS "Hour",
COUNT(*) AS "Events"
FROM events
WHERE LOGSOURCENAME(logsourceid) = 'Firewall-01'
GROUP BY "Hour"
ORDER BY "Hour"
LAST 24 HOURSA source that goes quiet at certain hours is an early warning of a collection problem or device outage.
Performance Tips
- Narrow the time range: it has the biggest impact on query duration.
- Start with indexed fields: filtering on source IP, destination IP, log source or username is much faster than payload search.
- Turn frequently searched payload values into custom properties so raw text isn’t scanned every time.
- Limit results:
LIMITand grouping reduce how much data comes back to the UI. - Save your queries: store frequently used searches as Saved Searches and share them with your team.
In QRadar 7.6, reference-set-filtered searches became up to 5x faster and custom event properties can hold multiple values that AQL evaluates. See our QRadar 7.6 what’s new guide for details.
Common Mistakes
- Use double quotes for aliases with spaces and single quotes for string values; mixing them causes errors.
- When you use
GROUP BY, every non-aggregated field you select must also be grouped. - Put the time clause (
LAST ...) at the very end of the query, not insideWHERE. - Some functions vary between QRadar versions; check the official AQL reference for your version.
Frequently Asked Questions
What’s the difference between AQL and SQL?
AQL uses SQL-like syntax but is specific to QRadar’s Ariel database. It adds QRadar-specific functions such as LOGSOURCENAME() and time clauses like LAST 24 HOURS, and it doesn’t support some SQL features such as JOIN.
Can an AQL query become a rule?
AQL queries don’t become correlation rules directly. You can, however, rebuild the same logic (threshold, grouping, time window) with rule wizard tests. Validating a behavior in AQL first and then turning it into a rule helps reduce false positives.
Why is my query so slow?
The most common reasons are a wide time range and text search on payloads. Narrow the time range and filter by log source or IP first.




