Find the top 5 most expensive items in the database.

To find the top 5 most expensive items in the database, write a SQL query that orders the items by price in descending order.

Problem

Write a SQL query to find the top 5 most expensive items in the database.
Example input:
| item_id | item_name | price |
|---------|-----------|-------|
| 1       | Item A    | 100   |
| 2       | Item B    | 200   |
| 3       | Item C    | 300   |
| 4       | Item D    | 400   |
| 5       | Item E    | 500   |
Example output:
| item_id | item_name | price |
|---------|-----------|-------|
| 5       | Item E    | 500   |
| 4       | Item D    | 400   |
| 3       | Item C    | 300   |
| 2       | Item B    | 200   |
| 1       | Item A    | 100   |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT * FROM items ORDER BY price DESC LIMIT 5;

/*

The solution above is optimal because it uses the ORDER BY and LIMIT clauses to sort the items by price in descending order and then limit the results to the top 5 items.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the ORDER BY and LIMIT clauses to sort the items by price in descending order and then limit the results to the top 5 items.

Evaluated at: 2022-11-23 08:16:13