Sort your subquery highest to lowest and then take the first row with LIMIT 1.
Select *
FROM customer_table
WHERE customer_ID = (
SELECT customer_ID
FROM audit_table
ORDER BY USED DESC
LIMIT 1
)
You may want to consider what happens if two customers have the same value in USED. It looks like there is a tie between C001 & C002 but this query will only return one customer
2
Answers
Sort your subquery highest to lowest and then take the first row with
LIMIT 1
.You may want to consider what happens if two customers have the same value in
USED
. It looks like there is a tie betweenC001
&C002
but this query will only return one customerThis will select the first record from the result set ordered by used in descending order.