Skip to content
SQLSimplified
BackendQuestion 37 of 52

Optimizing ORDER BY with Indexes

Problem

You have a query: SELECT * FROM employees ORDER BY hire_date DESC LIMIT 10. It is slow because the database sorts the entire table in memory. Write a DDL query to create an index named idx_emp_hire on the employees table for hire_date so the database can fetch pre-sorted records.

Database Schema

This problem acts as a scratchpad. You will write your own DDL/DML or conceptual queries, so there is no predefined schema.

Try It

Loading playground environment...

Hint

Solution