Prepin
Log in

Latest Transaction

Approach / Explanation

In this scenario, the interviewer is requesting that you create a SQL query to fetch the latest transaction from a database. This may involve a table that holds records of financial transactions, business dealings, or any other time-stamped events. The crucial aspect of addressing this question is knowing how to sort data by date in SQL and selecting just a single record. Here are some steps to guide you in answering the question: First, ensure that the table includes a column that records the date and time for each transaction. This column might be named transaction_date , date_time , timestamp , or something similar. It’s important to correctly identify this column. Next, focus on sorting the data by date to easily pinpoint the most recent transaction record. You can achieve this using the SQL ORDER BY clause. Additionally, to retrieve only the most recent transaction, you need to limit the results to 1. This can be done with the LIMIT keyword in SQL. Finally, combine all these elements into a SQL SELECT statement.

Suggested Answer

Using the transactions table, which includes the columns: id , amount , and transaction_date : SELECT * FROM transactions ORDER BY transaction_date DESC LIMIT 1 ; This query retrieves all columns from the transactions table, sorts the entries by transaction_date in descending order—meaning the latest date appears first—and restricts the results to only one record, which will represent the most recent transaction.

Alternative Answer

Here’s another instance, derived from a table of business transactions named sales , which includes the columns: sale_id , product_id , quantity , and sale_date : SELECT sale_id , product_id , quantity FROM sales ORDER BY sale_date DESC LIMIT 1 ; This SQL statement will fetch the sale_id , product_id , and quantity for the latest sale based on the sale_date column.

Question Details

Difficulty & Category

Medium
sql

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.