SQL QuestSQL Interview Questions › Subqueries & CTEs

Cardholders Who Have Never Disputed a Charge

MediumFreeQuerying BasicsSubqueries & CTEsJoinsAggregation & Grouping

The other side of the chargeback question: who has never raised one? 147 of the 200 accounts in this book have no dispute against them, and "has none" is not a filter you can write with a JOIN and a WHERE — a join finds rows that exist. NOT EXISTS is the direct form: a correlated subquery that stops as soon as it finds one matching chargeback, and the row survives only when it finds none.

Return the 20 highest-spending such cardholders: account_id, email, country, txn_count (their transaction count) and total_spend (SUM of amount, rounded to 2 decimals). Order by total_spend descending, then account_id ascending.

LEFT JOIN chargebacks … WHERE c.chargeback_id IS NULL is the same answer written as an anti-join — it is worth writing both and seeing that they agree. What is NOT the same answer is WHERE c.account_id <> a.account_id, which is the mistake this pattern exists to prevent.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

accounts

account_idemailsignup_atcountrydevice_fingerprintip_blockstatus
1user1@example.com2026-02-24T00:00:00.000ZTRdev_13c0cdad41.116.196.153active
2user2@inbox.dev2025-05-13T00:00:00.000ZJPdev_26576d4938.98.201.102active
3user3@inbox.dev2026-04-25T00:00:00.000ZJPdev_42f1a115190.77.45.244flagged

transactions

txn_idaccount_idamounttxn_atmerchant_idlatlngstatus
1149151.842026-03-04T12:39:39.078Z2440.342-74.4092completed
22110.722026-03-04T13:04:50.641Z752.936613.3229completed
335158.782026-03-04T13:27:15.528Z2552.739713.3134completed

chargebacks

chargeback_idtxn_idaccount_idmerchant_idreason_codeopened_atresolved_atstatusrelated_chargeback_id
1816010service_not_received2026-03-06T16:52:17.429Z2026-04-06T16:52:17.429ZsplitNULL
21644216fraud_card_not_present2026-03-16T23:50:46.792Z2026-04-22T23:50:46.792Zopen1
31724820fraud_card_present2026-03-12T05:22:57.195Z2026-04-14T05:22:57.195Zcardholder_won2

Expected output: 150 user150@mail.test TR 12 10126.18; 140 user140@mail.test US 11 8867.9; ...

Hint

FROM accounts a JOIN transactions t ON t.account_id = a.account_id WHERE NOT EXISTS (SELECT 1 FROM chargebacks c WHERE c.account_id = a.account_id) GROUP BY a.account_id, a.email, a.country. The subquery's SELECT list is irrelevant — SELECT 1 is the convention because nothing reads it.

Concepts

SELECT Subquery JOIN GROUP BY SUM

Practise the topic: SQL practice questions · CTE practice · JOIN practice · GROUP BY exercises

In these company practice sets

Capital One · Revolut

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Department Roster with GROUP_CONCATMedium · FreeConsistent Director AnalysisMedium · FreeBelow Department AverageMedium · FreeHighest Total Salary Budget DepartmentMedium · FreeFare Imputation AnalysisMedium · FreeUNION ALL Dedup: Cross-Dataset SearchMedium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test