Skip to content
Sharp

SQL for Java Devs · interview question

Given a table 'orders' with columns 'id', 'customer_id', and 'amount', which PreparedStatement correctly retrieves orders for a specific customer, sorted by amount?

Multiple choiceHardchapter-8-curatedpremiumsql-for-java-devspreparedstatements
Choose one answer
Answer and explanation

Correct answer

D. PreparedStatement stmt = connection.prepareStatement("SELECT * FROM orders WHERE customer_id =? ORDER BY amount DESC"); stmt.setInt(1, customerId);

Why

The correct SQL statement uses 'ORDER BY' for sorting results. 'DESC' sorts the results in descending order, and setInt() correctly binds the integer parameter for customer_id.

Test yourself on SQL for Java Devs

A free test with instant, explained results. No account needed.

Start free test
All SQL for Java Devs questions →