Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Query Review

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Query Review. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Review this SQL query and table definition for Mercury and tell me what performance issues, security vulnerabilities, or anti-patterns you see.

Assess the query structure, parameter handling, indexing needs, authorization boundaries, and maintainability. Provide a corrected executable query using representative constant values rather than driver placeholders.

Output

  1. Return one row per settled payment for account 101 during January 2026.
  2. Include account_id, account_name, payment_id, amount, currency, and created_at.
  3. Order by created_at descending, then payment_id descending.

Schema

mercury_accounts
ColumnTypeDescription
account_idPKINTEGERUnique Mercury account identifier
account_nameVARCHAR(120)Display name for the account
mercury_payments
ColumnTypeDescription
payment_idPKBIGINTUnique payment identifier
account_idINTEGERAccount receiving or sending the payment
amountNUMERIC(14,2)Payment amount in the stated currency
currencyVARCHAR(3)ISO currency code
statusVARCHAR(20)Payment processing status
created_atTIMESTAMPTZPayment creation timestamp
Tablesmercury_accountsmercury_payments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results