SQL QuestSQL Interview Questions › Subqueries & CTEs

Combined Sales and Permits Activity

MediumFreeQuerying BasicsSubqueries & CTEs

Build a unified activity feed: 20 most recent DEED sales (label='SALE') + 20 most recent ISSUED permits (label='PERMIT'). For sales show document_date as activity_date, document_amt as amount, label='SALE'. For permits show issuance_date as activity_date, NULL as amount, label='PERMIT'. Order by activity_date descending.

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

sales

document_idrecord_typedoc_typerecorded_boroughdocument_datedocument_amtrecorded_datetime
2025081800333001ADEED12025-08-1410800000002025-08-18
2024012300948001ADEED12024-01-229630000002024-01-24
2025081800439001ADEED12025-08-148100000002025-08-20

permits

permit_idjob_idbblboroughpermit_typepermit_statuswork_typefiling_dateissuance_dateexpiration_datebldg_typeowner_business_nameowner_business_typepermittee_business_name
16884114017497564006730016QUEENSSGISSUEDNULL01/08/200401/08/200406/30/20042HIGH PERFORMANCE FITNESS CENTERPARTNERSHIPPAUL SIGNS INC
17567813018206613026080079BROOKLYNEWISSUEDMH09/02/200409/10/200409/10/20052NULL2022-05-09 00:00:00APEX REALTY CO. LLC 7183915300 O
31364022132894095540029QUEENSSGISSUEDNULL01/30/200604/11/200606/30/20062Doral Bank: 7188507290 2022INDIVIDUALWNITECH DESIGN INC DBA SPACESIGN

Expected output: Recent sales + permits chronological feed

Hint

Two SELECTs UNION ALL. Wrap each in a subquery so you can ORDER + LIMIT each side independently. Use NULL placeholder for amount in the permits side.

Concepts

SELECT UNION ALL Set Operations

Practise the topic: SQL practice questions · CTE practice

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