SQL query for 5 most recent articles from a table, sorted by published date

Write a SQL query that returns the 5 most recent articles from a table of articles, sorted by published date.

Problem

Write a SQL query that returns the 5 most recent articles from a table of articles, sorted by published date.
Example input:
| id | title | body | published_date |
|----|-------|------|----------------|
| 1  | Foo   | ...  | 2020-01-01     |
| 2  | Bar   | ...  | 2020-01-02     |
| 3  | Baz   | ...  | 2020-01-03     |
| 4  | Qux   | ...  | 2020-01-04     |
| 5  | Quux  | ...  | 2020-01-05     |
| 6  | Corge | ...  | 2020-01-06     |
Example output:
| id | title | body | published_date |
|----|-------|------|----------------|
| 2  | Bar   | ...  | 2020-01-02     |
| 3  | Baz   | ...  | 2020-01-03     |
| 4  | Qux   | ...  | 2020-01-04     |
| 5  | Quux  | ... | 2020-01-05     |
| 6  | Corge | ...  | 2020-01-06     |

Solution

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

/*

The solution above is optimal because it uses the ORDER BY and LIMIT clauses to sort the articles by published date in descending order and then limit the results to the 5 most recent articles.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL. The solution is optimal because it uses the ORDER BY and LIMIT clauses to sort the articles by published date in descending order and then limit the results to the 5 most recent articles.

Evaluated at: 2022-11-15 14:15:33