TL;DR
This report details SQL techniques used to catch transaction fraud, such as velocity, impossible travel, amount anomalies, and merchant activity patterns. These methods are applied across various transaction types to detect suspicious behavior.
Data professionals are increasingly relying on specific SQL patterns to detect transaction fraud across various industries, from credit cards to benefits programs. These techniques, proven effective in identifying suspicious activity, are grounded in simple, well-understood SQL queries that analyze transaction logs for abnormal patterns, without the need for machine learning or complex algorithms.
The core methods involve six key SQL patterns. The first is velocity analysis, which flags accounts with unusually high transaction frequency within short time windows, such as multiple transactions in a minute or hour. For example, queries count transactions per card within defined intervals, with thresholds set to identify rapid activity that may indicate stolen card use.
The second pattern, impossible travel detection, compares timestamps and locations of transactions to identify cases where a card is used in geographically distant locations within a timeframe that exceeds plausible travel speeds. This involves calculating distances using haversine formulas and filtering for travel faster than commercial jets, typically over 600 mph.
Amount anomalies form the third pattern, targeting transactions with round dollar amounts or just below common thresholds (e.g., $99.99 or $499.99), which often signal card testing or attempts to stay under fraud detection limits. These are identified through simple amount filters in SQL queries.
The fourth pattern examines merchant activity, focusing on merchants with an unusually high number of transactions from unrelated cards over a short period. This can indicate card skimming or compromised terminals, with queries aggregating transactions by merchant and applying thresholds for unique card counts and total amounts.
Additional patterns include detecting duplicate recipients in benefits transactions, regional skimming rings working across ZIP codes, and border-crossing fraud rings operating within tight timeframes. These patterns rely on straightforward SQL joins, window functions, and aggregations, making them accessible and scalable for many organizations.
Why It Matters
These SQL-based detection patterns provide organizations with a transparent, adaptable, and resource-efficient way to identify fraud in transaction logs. They are particularly valuable for institutions lacking advanced machine learning infrastructure or seeking explainable rules for compliance and audit purposes. Implementing these patterns can significantly reduce fraud losses and improve transaction security.
As fraud tactics evolve, these SQL patterns serve as a foundational toolkit that can be combined and refined, offering a versatile approach for various transaction types, including credit card processing, healthcare claims, and e-commerce.

Applied Fraud Detection with Python: Analytics, Anomaly Detection, and AML Systems at Scale
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Background
Traditional fraud detection has increasingly incorporated machine learning and AI; however, many organizations still rely heavily on rule-based approaches. The patterns described here are based on practical, well-understood SQL queries shared by data practitioners, emphasizing their simplicity and effectiveness. These techniques have been tested across different sectors, including government benefit programs, credit card fraud detection, and retail.
Recent discussions on Hacker News and industry forums highlight the continued relevance of these methods, especially in environments where transparency and explainability are critical. While more sophisticated methods exist, these SQL patterns offer a reliable first line of defense, especially when dealing with large logs of transactions.
“SQL patterns like velocity checks and impossible travel are straightforward yet powerful tools to flag suspicious activity without complex models.”
— A data analyst working in fraud detection
“These rule-based patterns are still highly relevant, especially for organizations that need transparency or lack resources for machine learning.”
— Security researcher on Hacker News

Master SQL in 15 Days: The Friendly, No-Nonsense Guide to Databases and Queries
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What Remains Unclear
While these SQL patterns are proven effective, the specific thresholds and configurations may vary by dataset and industry. It is not yet clear how well these methods perform against emerging, more sophisticated fraud tactics, or how they can be integrated with newer detection technologies.

Predictive Analytics for the Modern Enterprise: A Practitioner's Guide to Designing and Implementing Solutions
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What’s Next
Organizations are expected to continue refining these SQL patterns, possibly combining them with machine learning or anomaly detection systems. Next steps include testing these queries on live datasets, adjusting thresholds for specific use cases, and developing automated monitoring dashboards that leverage these patterns for real-time fraud detection.

Anti-Money Laundering Transaction Monitoring Systems Implementation: Finding Anomalies (Wiley and SAS Business Series)
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
Can these SQL patterns detect all types of transaction fraud?
No, these patterns are designed to catch common, rule-based suspicious behaviors. More sophisticated fraud schemes may require additional methods.
Are these techniques applicable to real-time fraud detection?
Yes, with appropriate automation and optimized queries, these patterns can be integrated into real-time monitoring systems.
Do these SQL patterns generate many false positives?
They can produce false positives, especially for legitimate high-frequency or regional activity. Whitelists and thresholds should be tuned accordingly.
Are these methods industry-specific?
While demonstrated on transaction logs, these patterns are broadly applicable across sectors with logged transaction data, including finance, healthcare, and retail.
What are the limitations of relying solely on SQL-based detection?
SQL patterns are rule-based and may not catch evolving or highly sophisticated fraud schemes. They should be part of a layered security approach.