SQL QuestSQL Interview Questions › Subqueries & CTEs

Active and Recently Failed

MediumFreeQuerying BasicsSubqueries & CTEs

Build a unified table of active vs recently failed banks. UNION the institutions table (label='ACTIVE') with failures since 2020 (label='FAILED'). Show name, state, status for both. Limit each side to 20 rows. Order by status, then name.

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

institutions

certnamecitystatezipcharter_classestablished_datetotal_assetstotal_depositstotal_equityoffice_countbank_class
628JPMorgan Chase Bank, National AssociationColumbusOH43240801/01/1824375266200026978420003359360005335N
3510Bank of America, National AssociationCharlotteNC282021304410/17/1904263682300021019680002462500003840N
7213Citibank, National AssociationSioux FallsSD57108146106/16/181218364360001465300000176530000958N

failures

certnamecitystatefailure_datepre_failure_assetspre_failure_depositsresolution_typeestimated_loss
57488METROPOLITAN CAPITAL B&TCHICAGONULL1/30/2026261185212152FAILURENULL
5520SANTA ANNA NATIONAL BANKSANTA ANNANULL6/27/20257693871376FAILURE23460
28611PULASKI SAVINGS BANKCHICAGONULL1/17/20254946642741FAILURE30284

Expected output: Combined view: 20 active + 20 failed

Hint

Two SELECTs UNION ALL. Labels via constant string. SUBSTR for year filter on failures.

Concepts

SELECT UNION ALL WHERE Set Operations

Practise the topic: SQL practice questions · CTE practice

In these company practice sets

Morgan Stanley

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