Finding the row with the highest value in a table

To find the row with the highest value in a table, you can use a simple SQL query. Just specify the name and value columns in the SELECT clause, and add a ORDER BY clause to sort the results by value in descending order. Then, use the LIMIT clause to only return the first row from the sorted results.

Problem

Given a table of data with three columns (id, name, and value), write a SQL query that returns the name and value of the row with the highest value.
Example input:
id | name | value
1  | foo  | 10
2  | bar  | 20
3  | baz  | 30
Example output:
name | value
baz  | 30

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT name, value
FROM table
ORDER BY value DESC
LIMIT 1;

/*

The solution above is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by value in descending order and then return the first row.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by value in descending order and then return the first row.

Evaluated at: 2022-11-11 04:16:02