Overview of SQL for Fraud Detection & Risk Analytics | DataSoSi
Intermediate · SQL for Fraud Detection & Risk Analytics

Overview of SQL for Fraud Detection

A practical foundation in how fraud and financial crime data is structured, stored, and queried — built for fraud analysts, risk analysts, and AML professionals.

Financial institutions, fintech companies, and e-commerce platforms rely on structured databases to monitor transactions and detect financial crime. Every action — a payment, login, transfer, or alert — is stored across interconnected tables. SQL enables fraud and AML analysts to move beyond static dashboards and directly investigate suspicious activity, trace transaction flows, identify high-risk customers, and support compliance decisions in real time.
Fraud & AML Focused
Industry-Standard Tables
Notes & Reference Guide

Learning Objectives

SQL for Fraud Detection & Risk Analytics is structured as a progressive journey — from understanding how fraud data is organized to hands-on detection querying to advanced investigation and AML analytics. Each part builds directly on the knowledge established in the previous one, mirroring how fraud and compliance professionals actually work.

Part 1
Fraud & Risk Data Foundations

How fraud and AML data is organized across core tables — customers, accounts, transactions, merchants, and devices. Learners develop a foundational understanding of how financial activity flows and how key fraud indicators are captured in structured data.

Part 2
Fraud Detection SQL Queries

Hands-on querying across multiple tables — joining transactions to accounts, identifying risky merchants, detecting unusual frequency patterns, and using GROUP BY and HAVING to surface abnormal or high-value activity.

Part 3
Fraud & AML Analytics

Advanced detection and investigation work — transaction anomaly detection, velocity checks, fraud alert and case analysis, customer risk evaluation, AML alert review, sanctions screening, and detecting suspicious relationships across accounts.

Course Goal

By the end of all three parts, learners will be able to work confidently with fraud and AML data — writing queries that detect anomalies, trace suspicious activity, and support real-world financial crime investigations using structured SQL.

Modern financial systems store fraud and AML data across structured tables that capture customer behavior, transaction activity, device access, and risk signals. Every table in this course reflects the real data infrastructure used by banks, fintech platforms, and compliance teams.

Part 1 — Foundations
customers Customer-level Who is performing transactions
Key Fields
customer_idnamedate_of_birthcountrykyc_statuscustomer_typeonboarding_date
Used For

Identifying who is behind an account or transaction. KYC (Know Your Customer) status, customer type, and onboarding date are key fraud indicators used to assess baseline risk.

accounts Account-level Financial accounts linked to customers
Key Fields
account_idcustomer_idaccount_typeaccount_statusopen_datebalancecurrency
Used For

Tracing all financial activity back to specific accounts. Account type, status, and balance changes are critical for detecting account takeover, dormant account abuse, and layering in money laundering schemes.

transactions Transaction-level Every financial event — the most important fraud table
Key Fields
transaction_idaccount_idmerchant_idamounttransaction_datetransaction_typelocationstatus
Used For

The primary table for all fraud detection work. Used for high-value transaction filtering, frequency analysis, unusual location detection, velocity checks, and identifying patterns that trigger alerts.

merchants Merchant-level Businesses where transactions occur
Key Fields
merchant_idmerchant_namemerchant_categorycountryrisk_level
Used For

Identifying high-risk merchant categories (e.g., gambling, crypto exchanges), suspicious geographic concentrations, and merchants disproportionately associated with fraud alerts.

devices Device-level Login devices, IP addresses, and access patterns
Key Fields
device_idcustomer_iddevice_typeip_addresslogin_timestamplocationis_trusted
Used For

Detecting account takeover — new or untrusted devices, logins from unusual locations, multiple accounts sharing an IP address, and abnormal login frequency patterns.

Parts 2 & 3 — Intermediate & Advanced
fraud_alerts Alert-level Triggered alerts on suspicious transactions or behavior
Key Fields
alert_idtransaction_idcustomer_idalert_typealert_datealert_statuspriority
Used For

The starting point of most fraud investigations. Used to triage open alerts by priority, identify repeat-alert customers, and link alerts back to specific transactions and accounts.

fraud_cases Investigation-level Open and closed fraud investigations
Key Fields
case_idalert_idcustomer_idcase_statusinvestigatoropened_dateresolution
Used For

Tracking investigations from alert to resolution. Used for analyst workload analysis, case outcome reporting, and identifying trends in confirmed fraud versus false positives.

aml_alerts AML alert-level Anti-money laundering monitoring alerts
Key Fields
aml_alert_idcustomer_idaccount_idalert_typealert_datestatustransaction_amount
Used For

Identifying customers and accounts flagged for suspicious AML patterns — structuring, rapid movement of funds, unusual international transfers, or activity inconsistent with customer profile.

sanctions_screening Compliance-level Results of screening against sanctions lists
Key Fields
screening_idcustomer_idscreening_datelist_namematch_statusmatch_score
Used For

Identifying customers who have matched or closely matched sanctions, PEP (Politically Exposed Person), or watchlist entries — a regulatory requirement for all financial institutions.

risk_scores Risk-level Assigned risk ratings per customer
Key Fields
score_idcustomer_idrisk_scorerisk_bandscore_datescore_reason
Used For

Segmenting customers by risk level (low, medium, high), identifying customers whose risk scores have increased over time, and prioritizing which customers require enhanced due diligence.

How the Tables Connect

All ten tables connect through shared keys — customer_id threads through every table, account_id links accounts to transactions and AML alerts, and transaction_id connects transactions to fraud alerts. Understanding these connections is what makes end-to-end fraud investigations possible in SQL.

customers  ·  risk_scores  ·  sanctions_screening
 — who the customer is and their risk profile
accounts  ·  devices
 — financial relationships and access patterns
transactions  ·  merchants
 — the activity being monitored for fraud
fraud_alerts  ·  aml_alerts
 — triggered signals from suspicious activity
fraud_cases
 — formal investigations opened from alerts
Core Principle

Before writing any query, always ask: Am I analyzing a customer, a transaction, or an investigation? The answer determines which table to start from and how every join should be structured.

Customer-Level
One Row = One Customer

Stores fixed identity and risk attributes — KYC status, customer type, onboarding date. Use for risk profiling, sanctions screening review, and identifying high-risk customer segments.

Transaction-Level
One Row = One Transaction

Stores each individual financial event. One customer generates many transaction-level rows — making this table the primary source for all detection work involving amounts, frequency, and timing.

Investigation-Level
One Row = One Alert or Case

Stores triggered alerts and opened cases. Links back to specific transactions and customers. Use for triage, workload analysis, and measuring investigation outcomes and resolution rates.

The Full Data Hierarchy

Level Table(s) Relationship Example Fraud Question
Customer customers · risk_scores 1 row per customer "Which customers have a high risk band?"
Account accounts Many rows per customer "Which accounts have had status changes recently?"
Transaction transactions Many rows per account "Which transactions exceed $10,000 in the last 7 days?"
Alert fraud_alerts · aml_alerts Many rows per transaction or customer "Which open alerts are classified as high priority?"
Investigation fraud_cases Many rows per alert "How many cases were resolved as confirmed fraud last quarter?"
Golden Rule

Always verify row counts after joining. A customer joined to their transactions will produce one row per transaction — not one row per customer. Counting customers with COUNT(*) after such a join will overcount. Use COUNT(DISTINCT customer_id) whenever the question is about people, not events.

Fraud and AML analysis is built around a set of core fields that appear across nearly every detection query. Understanding what each field means — and how it behaves — is essential before writing any SQL for financial crime analytics.

Transaction Fields — The Detection Engine

The transactions table fields drive the majority of fraud detection work. Almost every fraud query either filters, aggregates, or compares values from these fields.

Field Why It Matters in Fraud Detection
amount High-value transactions are a primary fraud signal. Filtering for amounts above thresholds or deviating from a customer's normal range is a core detection technique.
transaction_date Timestamps power velocity checks — detecting multiple transactions in a short window. Also used for after-hours activity detection and time-of-day pattern analysis.
transaction_type Distinguishes payments, transfers, and withdrawals. Rapid transfers between accounts are a key money laundering indicator.
location Transactions from unusual or high-risk locations — or from multiple countries in a short time window — are strong fraud signals.
status Declined, reversed, or pending transactions often indicate fraud attempts. Declined-then-approved patterns are a common card testing signal.

Status & Risk Flag Fields

Status fields across multiple tables act as the first line of filtering in fraud queries. Understanding the typical values in each field is essential for accurate detection logic.

Field Table Typical Values Used To Identify
alert_status fraud_alerts Open, Reviewed, Closed, Escalated Unresolved alerts requiring investigation
case_status fraud_cases Open, Under Review, Confirmed Fraud, False Positive, Closed Investigation outcomes and analyst workload
risk_band risk_scores Low, Medium, High, Critical Customers requiring enhanced due diligence
match_status sanctions_screening No Match, Potential Match, Confirmed Match Customers who may be on prohibited lists
is_trusted devices TRUE / FALSE Account access from unrecognized devices
kyc_status customers Verified, Pending, Failed, Expired Customers with incomplete or failed identity verification

Key Questions These Fields Answer

Fraud Question Field(s) Table(s)
"Which transactions exceed $10,000?" amount transactions
"Which customers had 5+ transactions in 1 hour?" transaction_date · customer_id transactions + accounts
"Which open alerts are high priority?" alert_status · priority fraud_alerts
"Which customers are rated high risk?" risk_band risk_scores
"Which customers logged in from an untrusted device?" is_trusted · customer_id devices
"Which customers matched a sanctions list?" match_status sanctions_screening

Fraud and AML data does not live in a single system. Detection signals flow across transaction monitoring platforms, case management tools, compliance databases, and risk scoring engines. Understanding how data moves across these systems clarifies which table to query for each type of analytical question.

Transaction Monitoring
Real-Time Detection

Monitors all financial transactions as they occur, applying rules and thresholds to flag suspicious activity. Maps to transactions and fraud_alerts. Examples: FICO Falcon, Actimize, SAS Fraud.

Case Management
Investigation Workflow

Manages the lifecycle of fraud investigations from alert to resolution. Maps to fraud_alerts and fraud_cases. Examples: Actimize CMS, NICE Actimize, Oracle Financial Services.

AML Platform
Anti-Money Laundering

Monitors for structuring, layering, and unusual transaction patterns that indicate money laundering. Maps to aml_alerts and transactions. Examples: NICE Actimize AML, Temenos Financial Crime.

Compliance & Screening
Sanctions & Risk Scoring

Screens customers against global watchlists and maintains ongoing risk scores. Maps to sanctions_screening and risk_scores. Examples: World-Check, Dow Jones Risk & Compliance, LexisNexis.

The Fraud Detection Data Flow

  1. Customer is onboarded — identity is verified (KYC), a customer record is created, and an initial risk score is assigned. Data lands in customers and risk_scores.
  2. Account is opened — a financial account is linked to the customer in the accounts table. Device information is recorded in devices when the customer first logs in.
  3. Transactions occur — every payment, transfer, and purchase is recorded in the transactions table, linked to the account and merchant.
  4. Monitoring rules fire — when a transaction breaches a rule or threshold, a record is created in fraud_alerts or aml_alerts, linked to the transaction and customer.
  5. Analyst reviews the alert — an analyst queries the alert and its linked transaction, account, and customer data. If suspicious, a fraud_cases record is opened.
  6. Investigation is resolved — the case is updated with findings and a resolution. Risk scores may be recalculated and the customer's status updated based on the outcome.
Before Writing Any Query

Always identify which stage of the fraud lifecycle — detection, investigation, AML, or compliance — the question belongs to. That stage points directly to the primary table. Every other table in the query either adds context or applies a filter.

Overview — Key Takeaways

Five foundational principles from this introductory section.

Ten Tables

Customers, accounts, transactions, merchants, devices, fraud alerts, fraud cases, AML alerts, sanctions screening, and risk scores — each table maps to a distinct stage of the fraud detection and investigation lifecycle.

Three Levels

Customer, transaction, and investigation-level data. Joining correctly across these levels — and using COUNT(DISTINCT) when needed — prevents inflated counts and misleading detection results.

Key Fields

Amount, transaction_date, status, risk_band, alert_status, and is_trusted are the backbone of fraud SQL. These fields answer the most critical questions about what happened, when, and whether it was flagged.

Four Systems

Transaction monitoring, case management, AML platforms, and compliance screening each map to a distinct set of tables. Identifying the correct system domain before writing a query points directly to the right table.

Foundation First

Conceptual clarity prevents analytical errors. A solid understanding of how fraud data is structured — and how activity flows from transaction to alert to investigation — produces accurate, investigation-ready results from the very first query.

Enroll Now