Chapter 5 · JOINs
43. Each Loan with Its Most Recent Payment
Medium20 XPFinance
For each loan, show the most recent payment date and amount. Use a subquery to find the max payment_date per loan, then join back to get the payment details. Return loan_id, loan_type, principal, payment_date, and payment amount. Sort by payment_date descending. Limit to 30.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- loan_typeTEXT
- principalREAL
- interest_rateREAL
- term_monthsINT
- start_dateTEXT
- statusTEXT
- PKidINT
- FKloan_id→ loans.idINT
- payment_dateTEXT
- amountREAL
- principal_paidREAL
- interest_paidREAL
- remaining_balanceREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.