SQL for AML Analysts: The Queries That Cover Most of the Job 

13.11.26 12:15 PM - By NIYEAHMA

In short. Most anti-money laundering (AML) analyst work needs a small part of SQL: SELECT with a WHERE filter, a date range, GROUP BY with SUM and COUNT, HAVING, a two-table JOIN, a LEFT JOIN and a subquery. Nine query shapes cover most day-to-day tasks, from one customer's history to sizing a lookback population. 

Every generic SQL course teaches you to count orders and sum revenue. Then you sit down at a bank, and nobody asks you about orders. 


They ask how much cash went through an account in March. Whether four customers share a phone number. How many files a remediation would touch. So this article is organised around those questions. Each section gives the question, the query, then what the result tells you and what it does not. 


SQL stands for Structured Query Language. We executed every query below before publication. The data model is invented, and no platform or vendor schema appears anywhere.

What SQL an AML analyst actually uses in transaction monitoring work

Key point: about seven language features cover most analyst questions, and you can leave the rest for later. 

You are not asked to build anything, only to retrieve, filter, group and count. A narrow slice of the language. 

SQL feature   What it does  The AML task it serves 
 SELECT, FROM  Chooses columns from a table  Pulling a transaction extract 
 WHERE  Filters rows  Restricting to a customer, a channel or a date window 
 ORDER BY  Sorts the result  Reading a history in sequence 
 JOIN  Links two tables on a shared key  Getting customer detail onto transaction rows 
 LEFT JOIN  Keeps unmatched rows from the left table  Finding customers with no activity 
 GROUP BY, SUM, COUNT  Collapses rows into totals  Aggregating cash by customer and day 
 COUNT DISTINCT  Counts unique values  Sizing a population of customers, not rows 
 HAVING  Filters the groups after aggregation  Showing only totals above a set figure 
 CASE WHEN  Classifies a value inline  Splitting alert outcomes into columns 
 Subquery or WITH clause  Names an intermediate result  Comparing a period against a baseline 

Skip stored procedures, triggers, indexes, recursive queries, optimisation and, at first, window functions. 


Database differences matter less than people fear. SELECT, WHERE, GROUP BY, HAVING and JOIN behave the same in PostgreSQL, MySQL, Microsoft SQL Server, Oracle and SQLite. Date arithmetic is where they diverge, and I flag that where it bites.

The AML data model these SQL queries run against

Key point: you cannot write a useful query until you know which table holds which fact, and which key joins them. 

A generic four-table model carries every query in this article. It is illustrative and describes no real institution or system. Your firm's tables will be named differently and carry far more columns. Map yours onto this first.

Table   Key columns  What it holds  The usual gotcha 
 customers customer_id , full_name, customer_type, onboarding_date , risk_rating, country_of_residence, address_line, phone, status
One row per customer 
 One person can appear more than once if the firm never merged duplicates 
 accounts account_id, customer_id, account_type, currency, opened_date, closed_date, status
 One row per account, linked to a customer  Joint and related-party accounts break the assumption of one customer per account 
 transactions transaction_id, account_id, booking_date, value_date, direction, channel, amount, currency, amount_base, counterparty_name, counterparty_country One row per transaction, linked to an account amount is in the transaction currency, amount_base is converted. Summing the wrong one is the most common error in this article 
 alerts  alert_id, customer_id, account_id, scenario_code, alert_date, alert_status, outcome, closed_date, analyst_id One row per monitoring alert  An alert is not a case and not a filing. Three different populations 

Two things people get wrong. A customer identifier is not an account identifier, so you will join through accounts constantly. And booking_date and value_date are different dates: booking is when the system recorded it, value is when it took effect. Filter on one, reconcile against the other, and they will never agree. Dates carry a time zone even when the column does not show one, which is usually why an extract is off by a day at each end. For how this data is produced, see what an AML analyst actually does all day. 

Query 1: SQL to pull every transaction for one customer in a date window

Key point: this is the foundation query, and almost every other query in this article is a variation on it. 

The question you get asked: "Can you pull me everything on this customer for the first half of the year?" 

SELECT t.transaction_id, 

  t.booking_date, 

  t.value_date, 

  a.account_id, 

  t.direction, 

  t.channel, 

  t.amount_base, 

  t.currency, 

  t.counterparty_name, 

  t.counterparty_country 

FROM  transactions t 

JOIN  accounts a ON a.account_id = t.account_id 

WHERE  a.customer_id = 'CUST000123' 

AND  t.booking_date >= '2026-01-01' 

AND  t.booking_date <  '2026-07-01' 

ORDER BY t.booking_date, t.transaction_id; 

What it answers. Every recorded transaction on every account belonging to that customer, in booking-date order, across a six month window. 


What it misses, and the common mistake. Look at the date filter. Greater than or equal at the start, strictly less than at the end. Write <= '2026-06-30' instead and you silently drop everything timestamped later that day. A wrong date filter is the most frequent cause of a wrong answer in this work and it never announces itself. The query also misses accounts the customer controls but does not own, archived closed accounts, and anything under a duplicate customer record. 


Before you send the result anywhere, run the control count: 

SELECT COUNT(*)  AS row_count, 

  COUNT(DISTINCT a.account_id)  AS accounts_covered, 

  MIN(t.booking_date)  AS earliest, 

  MAX(t.booking_date)  AS latest, 

  SUM(CASE WHEN t.amount_base IS NULL THEN 1 ELSE 0 END) AS null_amounts 

FROM  transactions t 

JOIN  accounts a ON a.account_id = t.account_id 

WHERE  a.customer_id = 'CUST000123' 

AND  t.booking_date >= '2026-01-01' 

AND  t.booking_date <  '2026-07-01'; 

If accounts_covered says one and you know the customer has three, stop. Your join or your filter is wrong. 

Query 2: SQL GROUP BY, SUM and HAVING to aggregate cash activity against a threshold

Key point: GROUP BY with SUM and HAVING is the shape behind most aggregation questions in monitoring. 

The question you get asked: "Which customers took in more than the review figure in cash on a single day, and how does that look over a rolling week?" 


The figure below is an arbitrary placeholder you set. It is not any jurisdiction's reporting threshold and must not be read as one. 

SELECT a.customer_id, 

  t.booking_date, 

  COUNT(*)  AS cash_credits, 

  SUM(t.amount_base) AS day_total 

FROM  transactions t 

JOIN  accounts a ON a.account_id = t.account_id 

WHERE  t.channel  = 'CASH' 

AND  t.direction = 'CREDIT' 

AND  t.booking_date >= '2026-01-01' 

AND  t.booking_date <  '2026-07-01' 

GROUP BY a.customer_id, t.booking_date 

HAVING SUM(t.amount_base) >= 100000 

ORDER BY day_total DESC; 

A calendar day is rarely the right period. The same idea over a rolling seven days, without window functions so it runs almost anywhere: 

WITH daily AS ( 

  SELECT a.customer_id, 

  t.booking_date, 

  SUM(t.amount_base) AS day_total, 

  COUNT(*)  AS day_count 

  FROM  transactions t 

  JOIN  accounts a ON a.account_id = t.account_id 

  WHERE  t.channel  = 'CASH' 

  AND  t.direction = 'CREDIT' 

  AND  t.booking_date >= '2026-01-01' 

  AND  t.booking_date <  '2026-07-01' 

  GROUP BY a.customer_id, t.booking_date 

) 

SELECT d1.customer_id, 

  d1.booking_date  AS window_end_date, 

  SUM(d2.day_total) AS window_total, 

  SUM(d2.day_count) AS window_transactions 

FROM  daily d1 

JOIN  daily d2 

  ON  d2.customer_id  = d1.customer_id 

 AND  d2.booking_date <= d1.booking_date 

 AND  d2.booking_date >  DATEADD(day, -7, d1.booking_date) 

GROUP BY d1.customer_id, d1.booking_date 

HAVING SUM(d2.day_total) >= 100000 

ORDER BY window_total DESC; 

That DATEADDd1.booking_date - INTERVAL '7 days'. MySQL: DATE_SUB(d1.booking_date, INTERVAL 7 DAY). Oracle: d1.booking_date - 7. SQLite: DATE(d1.booking_date, '-7 day'). 


What it answers. Which customers crossed a figure you chose, on which days, and how the same activity looks across a moving window rather than a calendar boundary. 


What it misses. Anything not coded as cash in channel, which you will not know about unless you ask. The customer is the unit, so related parties acting together are not aggregated. And a genuinely cash intensive business tops this list every month, which tells you nothing on its own.

Query 3: SQL to find round numbers and repeating transaction amounts

Key point: a round or repeated amount is a prompt to look at a file, never a conclusion about it. 

SELECT a.customer_id, 

  t.amount_base, 

  CASE WHEN t.amount_base = ROUND(t.amount_base / 1000.0, 0) * 1000.0 

  THEN 'MULTIPLE_OF_1000' ELSE 'NOT_ROUND' END AS roundness, 

  COUNT(*)  AS times_seen, 

  COUNT(DISTINCT t.account_id) AS accounts_used, 

  MIN(t.booking_date)  AS first_seen, 

  MAX(t.booking_date)  AS last_seen 

FROM  transactions t 

JOIN  accounts a ON a.account_id = t.account_id 

WHERE  t.booking_date >= '2026-01-01' 

AND  t.booking_date <  '2026-07-01' 

GROUP BY a.customer_id, t.amount_base, 

  CASE WHEN t.amount_base = ROUND(t.amount_base / 1000.0, 0) * 1000.0 

  THEN 'MULTIPLE_OF_1000' ELSE 'NOT_ROUND' END 

HAVING COUNT(*) >= 3 

ORDER BY times_seen DESC, t.amount_base DESC; 

What it answers. Which exact amounts repeat, how often, across how many of that customer's accounts, and whether the amount is a round multiple. 


What it misses, and why this is only a prompt. Salaries repeat. Rent, loan instalments, standing orders and school fees repeat, and most are round. On a retail book this returns a great deal of ordinary life. Its value is comparative: an amount that repeats and matches nothing you know about the customer's stated business is worth ten minutes of reading. 


One technical warning. Comparing decimals with equals is fragile, because stored amounts carry tiny representation differences. Where your database offers a modulo function, prefer it, and test on known rows first. 


Detecting a pattern is where the query stops. What the pattern means is the analyst's work, and it belongs in the file, not the result set.

Query 4: a SQL self-join to find linked parties who share an address, a phone or a device

Key point: this is a self-join, and the mistake everyone makes is forgetting to exclude the row matching itself. 

The question you get asked: "Do any of these customers connect to each other?" 

SELECT c1.customer_id  AS customer_id, 

  c2.customer_id  AS linked_customer_id, 

  c1.address_line AS shared_address, 

  c1.risk_rating  AS customer_risk, 

  c2.risk_rating  AS linked_risk 

FROM  customers c1 

JOIN  customers c2 

  ON  c2.address_line = c1.address_line 

 AND  c2.customer_id  > c1.customer_id 

WHERE  c1.address_line IS NOT NULL 

AND  c1.address_line <> '' 

ORDER BY c1.address_line, c1.customer_id; 

Two details do the work. Without a condition comparing c2.customer_id to c1.customer_id, every customer links to themselves. Greater than instead of not-equal returns each pair once rather than twice, which stops you double counting. 


To size the clusters before reading any of them: 

SELECT address_line, 

  COUNT(*) AS customers_at_address 

FROM  customers 

WHERE  address_line IS NOT NULL 

AND  address_line <> '' 

GROUP BY address_line 

HAVING COUNT(*) > 1 

ORDER BY customers_at_address DESC; 

What it answers. Which customers share an exact value in a chosen field. Swap address_line for phone, an email column or a device identifier and the shape is identical. 

What it misses. Almost everything about how addresses are really stored. "Flat 2, 14 High St" and "14 High Street, Apt 2" are the same place and will never match on equality. Free-text fields need normalising first. 


False links are the bigger problem. A serviced office, a formation agent's address or a corporate switchboard produces clusters of dozens with no relationship at all. Three customers sharing an attribute is worth reading. Three hundred is a data artefact, and treating it as a network is how an investigation gets expensive fast. The research that turns a link into a finding is covered in the OSINT research sequence for enhanced due diligence. OSINT means open-source intelligence. 

Query 5: SQL to size a KYC lookback population before you commit to it

Key point: this number decides budget, resourcing and how long the remediation runs, so it has to be reproducible by someone who was not there. 

The question you get asked: "If we look back two years on this segment, how many customers and how many transactions are we talking about?" 

SELECT c.risk_rating, 

  c.country_of_residence, 

  COUNT(DISTINCT c.customer_id) AS customers_in_scope, 

  COUNT(DISTINCT a.account_id)  AS accounts_in_scope, 

  COUNT(t.transaction_id)  AS transactions_in_scope, 

  MIN(t.booking_date)  AS earliest, 

  MAX(t.booking_date)  AS latest 

FROM  customers c 

LEFT JOIN accounts a 

  ON a.customer_id = c.customer_id 

LEFT JOIN transactions t 

  ON t.account_id = a.account_id 

  AND t.booking_date >= '2024-07-01' 

  AND t.booking_date <  '2026-07-01' 

WHERE  c.onboarding_date < '2026-07-01' 

GROUP BY c.risk_rating, c.country_of_residence 

ORDER BY customers_in_scope DESC; 

What it answers. How many customers, accounts and transactions fall inside a defined scope, split by segment so you can see where the volume sits. A know your customer (KYC) remediation is scoped from exactly this output. The split by risk_rating, which holds the customer risk rating the firm assigned at onboarding or at the last review, is what tells you whether the work is concentrated in the segment you expected or sitting somewhere nobody budgeted for. 


What it misses, and the mistake that halves your number. The date filter on transactions sits in the ON clause, not in WHERE. Move it to WHERE and the LEFT JOIN quietly becomes an inner join, so every customer with no activity in the window disappears. Those customers are still in scope. I have seen a remediation scoped from a number that was wrong for exactly this reason. It also misses archived customers and counts a duplicate twice. 


Save the query text, the run date, and the row counts with the number. A lookback figure quoted without the query behind it cannot be defended six months later, and that is when it gets questioned. If the remediation exists because a rule was found wanting, see how a monitoring rule's threshold is set and defended. 

Query 6: SQL to report the AML alert population by scenario and outcome

Key point: alerts raised, alerts escalated and reports filed are three different numbers, and mixing them is the fastest way to lose an argument about tuning. 

The question you get asked: "Give me last year's alerts by scenario, with what happened to them." 

SELECT al.scenario_code, 

  COUNT(*)  AS alerts_raised, 

  COUNT(DISTINCT al.customer_id) AS customers_alerted, 

  SUM(CASE WHEN al.alert_status = 'OPEN' THEN 1 ELSE 0 END)  AS still_open, 

  SUM(CASE WHEN al.outcome = 'CLOSED_NO_ACTION' THEN 1 ELSE 0 END)  AS closed_no_action, 

  SUM(CASE WHEN al.outcome = 'ESCALATED' THEN 1 ELSE 0 END)  AS escalated, 

  SUM(CASE WHEN al.outcome = 'REPORTED' THEN 1 ELSE 0 END)  AS reported 

FROM  alerts al 

WHERE  al.alert_date >= '2025-07-01' 

AND  al.alert_date <  '2026-07-01' 

GROUP BY al.scenario_code 

ORDER BY alerts_raised DESC; 

CASE WHEN inside SUM turns rows into columns. It is the most useful single trick here and works in every database. 


The same output is the evidence base for any argument about alert triage capacity. It shows which scenario produces the volume, what share of that volume closes with no action, and how much of it reaches a filing. Bring those three numbers to a resourcing conversation and it stops being a conversation about how hard everyone is working. 


What it answers. For each scenario: alerts produced, distinct customers touched, how many are still open, and how the closed ones were dispositioned. 


What it misses. Open alerts have no outcome yet, so a period still being worked understates escalations and filings. Duplicates may or may not be flagged. And a customer alerting on four scenarios appears in four rows, so the columns do not add to a customer count. Read that before quoting a productivity figure. Whether the resulting queue is a tuning, training or headcount problem is a separate diagnosis.

Query 7: SQL to find activity that changed against the customer's own baseline

Key point: the useful comparison is a customer against their own history, not against the book average. 

The question you get asked: "Whose behaviour changed this month?" 

WITH baseline AS ( 

  SELECT a.customer_id, 

  SUM(t.amount_base) / 6.0 AS avg_monthly_value, 

  COUNT(*) / 6.0  AS avg_monthly_count 

  FROM  transactions t 

  JOIN  accounts a ON a.account_id = t.account_id 

  WHERE  t.booking_date >= '2025-07-01' 

  AND  t.booking_date <  '2026-01-01' 

  GROUP BY a.customer_id 

), 

recent AS ( 

  SELECT a.customer_id, 

  SUM(t.amount_base) AS period_value, 

  COUNT(*)  AS period_count 

  FROM  transactions t 

  JOIN  accounts a ON a.account_id = t.account_id 

  WHERE  t.booking_date >= '2026-06-01' 

  AND  t.booking_date <  '2026-07-01' 

  GROUP BY a.customer_id 

) 

SELECT r.customer_id, 

  b.avg_monthly_value, 

  r.period_value, 

  r.period_value / b.avg_monthly_value AS value_ratio, 

  b.avg_monthly_count, 

  r.period_count 

FROM  recent r 

JOIN  baseline b ON b.customer_id = r.customer_id 

WHERE  b.avg_monthly_value > 0 

AND  r.period_value > b.avg_monthly_value * 3 

ORDER BY value_ratio DESC; 

What it answers. Which customers moved materially more value in the recent period than their own six month average, ranked by how far the change goes. 


What it misses. A tiny baseline produces an enormous ratio from an ordinary transaction, so put a floor on avg_monthly_value first. Seasonal businesses breach their own baseline every year on schedule. And the inner join means a recent joiner with no baseline never appears, which may be the population you most want to see. Change against a baseline is a question, not an answer. The customer may have sold a property, received an inheritance or won a contract, and none of that is in your database. 

Query 8: a SQL LEFT JOIN to find activity that stopped

Key point: absence is a real signal and almost nobody queries for it, because absence is harder to express than presence. 

The question you get asked: "Which of our higher risk customers have gone quiet?" 

SELECT c.customer_id, 

  c.risk_rating, 

  MAX(t.booking_date)  AS last_transaction_date, 

  COUNT(t.transaction_id) AS transactions_seen 

FROM  customers c 

JOIN  accounts a ON a.customer_id = c.customer_id 

LEFT JOIN transactions t 

  ON t.account_id = a.account_id 

  AND t.booking_date < '2026-07-01' 

WHERE  c.status = 'ACTIVE' 

AND  a.status = 'ACTIVE' 

GROUP BY c.customer_id, c.risk_rating 

HAVING MAX(t.booking_date) < '2026-04-01' 

  OR MAX(t.booking_date) IS NULL 

ORDER BY last_transaction_date; 

What it answers. Open customers with open accounts whose most recent transaction is older than a date you choose, including those who have never transacted at all. The IS NULL branch is what catches the never-active accounts, and it is the branch people forget. 


What it misses. Dormancy is usually innocent. People move banks, close businesses, retire and forget. What makes the query worth running is the pairing: an account opened with a full onboarding story and then never used the way that story described. It is blind to activity that moved to a channel your transactions table does not carry.

Query 9: SQL to reconcile transaction monitoring against what the bank holds

Key point: the monitoring system sees a feed, and the feed is not the whole bank. The gap between the two is a control question, not a data question. 

The question you get asked, usually by an auditor: "How do you know everything in scope was actually monitored?" 


An AML audit puts it in close to those words, and the only answer that survives is a number with a query behind it. "The system covers everything" is not an answer, because nobody in the room can test it. 


Start with control totals from the core records, by month and channel:

SELECT SUBSTR(t.booking_date, 1, 7) AS booking_month, 

  t.channel, 

  COUNT(*)  AS transactions, 

  SUM(t.amount_base)  AS total_value, 

  COUNT(DISTINCT t.account_id) AS accounts_active 

FROM  transactions t 

WHERE  t.booking_date >= '2026-01-01' 

AND  t.booking_date <  '2026-07-01' 

GROUP BY SUBSTR(t.booking_date, 1, 7), t.channel 

ORDER BY booking_month, t.channel; 

SUBSTR on a date stored as text is the portable way to get a month. PostgreSQL: 
TO_CHAR(t.booking_date, 'YYYY-MM'). MySQL: DATE_FORMAT(t.booking_date, '%Y-%m'). SQL Server:  FORMAT(t.booking_date, 'yyyy-MM'). Oracle: TO_CHAR(t.booking_date, 'YYYY-MM'). SQLite:  STRFTIME('%Y-%m', t.booking_date). 

Then look for referential breaks, which is where feed drift shows up first:

SELECT al.alert_id, 

  al.customer_id, 

  al.alert_date, 

  al.scenario_code 

FROM  alerts al 

LEFT JOIN customers c ON c.customer_id = al.customer_id 

WHERE  c.customer_id IS NULL 

ORDER BY al.alert_date; 

What it answers. Monthly counts and values you can put next to the monitoring system's own reported figures, plus any alert pointing at a customer identifier the core system does not hold. 


What it misses. Why the two disagree. A missing product, a delayed feed, a conversion rate applied differently, an undocumented filter inside the monitoring configuration. Each produces a difference and only one is a data error. When the numbers do not agree, do not quietly reconcile them in a spreadsheet. Write down the difference, the period and the two sources, and take it to whoever owns the feed.

Where these SQL queries touch a UAE AML legal obligation

Key point: extracting and organising this data is part of the record-keeping and ongoing monitoring duty in the UAE, not an optional analytical nicety. 

Cabinet Resolution No. 134 of 2025, the Executive Regulations of Federal Decree-Law No. 10 of 2025, sets the ongoing monitoring duty at Article 8(1): 

"Scrutinizing Transactions carried out throughout the duration of the Business Relationship to ensure that such Transactions are consistent with the information available thereto regarding the Customer, the nature of their activities, and the risks they represent, including, where necessary, the source of funds." 

Queries 1, 2, 7 and 8 are ways of asking that question of the data. 


Article 25(3) of the same Resolution sets the standard your records have to meet: 

"Financial Institutions, Designated Non-Financial Businesses and Professions, and Virtual Asset Service Providers shall organize retained records, documents, and instruments in a manner sufficient to permit the reconstruction of individual Transactions, data analysis, and the tracing of financial transactions, so as to be capable, where necessary, of providing evidence for prosecution of criminal activity." 

Reconstruction, data analysis and tracing. That is the test a lookback extract or a reconciliation has to survive. Article 25 also sets retention at not less than five years and requires records to be available promptly on request.


These are UAE provisions. Other regimes word it differently and reach much the same place. The instrument was read in full and quoted word for word on 30 August 2026. 

Five habits that separate a usable SQL result from a wrong one

Key point: the query is the easy part. What you do around it decides whether anyone can rely on the answer. 

1. Count the rows before you read them. Run a COUNT with MIN and MAX of the date column first. If either number is implausible, the filter is wrong. Nobody has regretted the extra thirty seconds. 


2. Treat the date filter as the prime suspect. Inclusive at the start, exclusive at the end. Know whether you are on booking date or value date, and whether the column carries a time and a time zone. Most wrong answers in this work are date answers. 


3. Never present a result without saying what it excluded. One line under the table: which channels, which date basis, which statuses, which customers a join dropped. A result without its exclusions is not evidence, and a reviewer who finds them later will discount everything else you produced. 


4. The monitoring system and the bank hold different data. The system sees the feed it was given, transformed the way it was configured. The core record is the bank's own account of what happened. When someone asks how many transactions there were, ask which of the two they mean. 


5. A pattern is not a finding. SQL tells you what happened. It will not tell you why, whether the customer's business explains it, or what anyone intended. That judgement is yours and it has to be written down. Turning a result into something a reader can follow is covered in turning the query output into a narrative. STR means suspicious transaction report and SAR means suspicious activity report, depending on your jurisdiction.

When to stop guessing and ask the AML data owner

Key point: guessing at a column meaning is the one failure in this work that a reviewer cannot detect and cannot forgive. 

Stop and ask when any of these is true. 

  • The column name is ambiguous and you are inferring its meaning from the values. status, type, flag and code are the usual offenders. 

  • Two sources disagree and you cannot explain the difference. 

  • The row count changes materially when you change something that should not have mattered. 

  • You are about to quote a number for a budget, a resourcing decision, a regulatory response or a board paper. 

  • You do not know whether a column is populated for all periods, or only since a system change. 

Ask in writing, name the table and column, state what you assumed, and keep the reply. That reply is part of the audit trail for your number. Guessing costs nothing on the day and everything when the number is challenged. 

The nine query sheet: SQL for AML analysts at a glance

Key point: this is the whole article in one table, and you may reuse it. 

Table 3 compresses the nine queries onto one page: the question each one answers, and the failure that most often makes it answer something else instead. Read the fourth column first. The query shapes are the easy half. The error column is where the content actually sits, because a statement that runs cleanly and answers the wrong question looks exactly like one that is right. 


The mistake people make with a sheet like this is treating it as nine separate things to learn. It is closer to one query with eight variations. Queries 2, 3, 6 and 7 are the same aggregate-then-filter shape pointed at different columns, and Queries 5 and 8 are both LEFT JOIN questions. Use the sheet to name the query you need before you open an editor, rather than as code to copy.

# Query What it answers  What most often goes wrong 
1Customer transactions in a date window 
Every transaction on every account of one customer, in order 
 Inclusive end date silently drops the final day. Accounts controlled but not owned are missed 
2Cash aggregated against a threshold 
Which customers crossed a figure you set, per day and per rolling window 
 Only sees what is coded as cash. Related parties are not aggregated together 
3Round and repeating amounts 
Which exact amounts repeat, how often, across how many accounts 
 Salaries, rent and instalments dominate the result. Decimal equality is fragile 
4Linked parties by shared attribute 
Which customers share an address, phone, email or device 
 The self-match is not excluded, and shared-office addresses create huge false clusters 
5Lookback population sizing 
Customers, accounts and transactions inside a defined scope, by segment 
 A date filter moved into WHERE turns the LEFT JOIN into an inner join and hides zero-activity customers 
 6 Alert population by scenario and outcome  Alerts raised, still open, closed, escalated and reported, per scenario  Open alerts have no outcome yet, so recent periods understate escalations and filings 
 7 Change against the customer's own baseline Customers moving materially more than their own recent average  Tiny baselines produce huge ratios. New customers have no baseline and never appear 
 8 Activity that stopped  Open customers and accounts with no recent activity, including never-active ones  Forgetting the IS NULL branch, which is exactly the population you wanted 
 9 Monitoring against core reconciliation  Monthly control totals and alerts pointing at unknown customers  It shows the difference but never the cause. Do not close the gap yourself 

The nine are also the spine of a short applied module we teach, one query per lesson with an exercise attached. 

How to learn enough SQL to be useful, without becoming a data engineer

Key point: the goal is to answer your own questions unaided, not to pass a developer interview. 

Be honest about the ceiling. You need to retrieve, filter, group, count and join. You don't need to design a schema, tune an index, or build a pipeline. Those are different jobs for people trained for them. 


A workable route. Install SQLite or DuckDB, both single files with no server. Create the four tables above and fill them with a few thousand rows of obviously fake data, with names like "Customer 41", not realistic personal details. Then work through the nine queries, breaking each on purpose to see what the error looks like. 


Don't practise on production, and don't copy real customer records to a laptop to learn on. That is a data protection breach, whatever your intention, and our course on Data Privacy for AML Professionals (UAE Edition) covers where those lines sit. 


The fastest progress comes from a real question. Take something you ask a colleague for every month and write it yourself. You will get it wrong twice, then you will own it.


Assistants will write most of these queries for you now. That raises the value of reading one and saying why it is wrong, which is the actual skill. We cover the wider picture of where automation fits into AML screening.

How to ask your firm for read-only database access properly

Key point: most analysts never get access because of how they ask, not because the answer was always going to be no. 

"Can I have database access" is a request nobody can approve. It has no scope, no purpose and no limit, so the safe answer is no. Ask like this instead. 


Name the read-only role. SELECT permission only, on named tables or a reporting view, with no ability to write, update or delete. 


Name the environment. A reporting replica or a data warehouse, not the production system that is processing payments. 


Name the purpose and the recurring task. "I produce the monthly cash aggregation and the alert outcome summary, and I currently wait days for each." A named recurring task turns your request into a resourcing argument. 


Accept the controls before they are imposed. Row limits. No export outside approved systems. No customer records onto personal devices. Queries logged. Saying this first removes most of the objections. 


Name your sponsor and your reviewer, and offer a review point: access for one quarter, then a look at what you produced with it. 


Route the request through your Compliance Officer or MLRO and your data owner together. UAE federal law calls the role Compliance Officer. The Dubai International Financial Centre and the Abu Dhabi Global Market say MLRO, meaning money laundering reporting officer. United States law says BSA Officer, under the Bank Secrecy Act. 


If you are earlier in your career, we set out the analyst skills hiring managers actually test and AML and compliance roles in the UAE and what they pay. A data skill is one of the few things that moves an analyst between pay bands rather than along one, and AML salary bands by role, region and employer type shows where those bands sit.

We sell AML training, so here is our interest in this

Pro AML Training sells applied anti-money laundering and counter financing of terrorism training. CFT means counter financing of terrorism. This article says the queries matter more than the certificate, which is convenient for us, and you should factor that in. 


So judge it on the part that costs you nothing. Every query above is published in full. Copy them, run them against your own fake data, and see whether the "what it misses" notes match what you find. If they do not, the article is wrong, and you have lost an hour. 


If you want to go deeper on the transaction monitoring side, our course on Advanced Transaction Monitoring for Trading, Funds and Wealth Operations is built around these decisions. If you have no budget, our course on adapting to FATF grey list updates is free. Or Explore Courses. 


On certificates, my view hasn't changed: they open doors, and they don't teach this. I set out the full argument in what an AML certification actually buys you. If you are studying for CAMS while holding down the job, what CAMS exam prep actually takes alongside full-time work is honest about the time cost, and it is the same set of evenings you would otherwise spend learning to query your own data.

Frequently asked questions about SQL for AML analysts

Not universally, but it appears on a large share of adverts and it changes what you can do without waiting on someone else. Analysts who pull their own data see patterns across files rather than inside one. 
SELECT, WHERE, ORDER BY, JOIN, LEFT JOIN, GROUP BY with SUM and COUNT, COUNT DISTINCT, HAVING, CASE WHEN and a WITH clause. That set writes every query in this article. I will not give an hours estimate, because it depends on how often you use it. 

The system runs configured rules continuously across the whole book and raises alerts. SQL answers one specific question once, when you ask it. TM means transaction monitoring. You use SQL to interrogate what the system produced, and to check what it did not see. 

You can prototype the logic, which is genuinely useful before anyone builds anything. A production rule needs governance, documented thresholds, tuning evidence and validation. 

Any of them. The differences at this level are small and concentrate in date and string functions. SQLite or DuckDB are easiest to install, because each is a single file with no server. 

Different jobs. SQL retrieves and aggregates data close to where it lives. Python is better for anything iterative or statistical. Learn SQL first, because it answers more of what you are actually asked. 

Yes, and you must. Build the four tables in this article on your own machine and fill them with obviously fake rows. Never copy production customer records anywhere to learn on. 

The set of customers, accounts or transactions a remediation or historical review will cover, defined by a date range and a scope rule. Query 5 sizes it. The number drives budget, so it has to be reproducible. 

Join the customer table to itself on the shared attribute and exclude the self-match. Then check the size of each cluster before reading any of it. A shared serviced-office address will link hundreds of unrelated customers and prove nothing. 

Almost always an unintended join. Either two tables were joined without a condition, producing every combination of rows, or you joined on a column that is not unique on one side. Count each table separately, then count the join. 

Increasingly yes, and that is fine. It makes reviewing a query the more valuable skill, because one that runs cleanly and answers the wrong question looks exactly like one that is right. 

Only with read-only access, on a reporting environment rather than production, for an approved purpose, with the extract handled under your firm's data protection rules. 

Not to start. Every query here runs without them. They earn their place when you need running totals, rankings within a customer, or a previous-row comparison. 

Shapes, not trivia. Aggregate by customer and filter the totals. Explain the difference between an inner join and a left join. Describe how you would find duplicates. If you can talk through Queries 1, 5 and 6, you can hold that conversation. 

About the author

Pathik Shah is the founder of ProAML Training. He holds CAMS and is a Fellow Chartered Accountant (FCA) and a Certified Information Systems Auditor (CISA), and he holds the DISA and FAFD qualifications from the Institute of Chartered 
Accountants of India. He has spent more than 28 years in governance, risk and compliance, and advises regulated 
firms across the UAE and the GCC on AML and CFT programmes. He writes about the difference between knowing the 
rules and doing the work.

NIYEAHMA