Complete the code to select the best index for faster query execution.
SELECT * FROM employees WHERE salary > 50000 ORDER BY [1];
The query orders results by salary, so using an index on the salary column helps speed up sorting and filtering.
Complete the code to rewrite the query using a join instead of a subquery for better performance.
SELECT e.name, d.department_name FROM employees e [1] departments d ON e.department_id = d.id;Using an INNER JOIN replaces the subquery and returns only matching rows, which is often faster.
Fix the error in the query by choosing the correct clause to limit the number of rows returned.
SELECT * FROM sales [1] 10;
The LIMIT clause restricts the number of rows returned by the query, which helps optimize performance when only a subset is needed.
Fill both blanks to create a query that uses an index and filters rows efficiently.
SELECT * FROM orders WHERE [1] = 'shipped' AND [2] > '2023-01-01';
Filtering by status and order_date helps the database use indexes on these columns to quickly find relevant rows.
Fill all three blanks to write a query that aggregates data efficiently using grouping and filtering.
SELECT [1], COUNT(*) AS total FROM sales WHERE [2] > 100 GROUP BY [3];
The query groups sales by region, counts the number of sales where the amount is greater than 100, and uses the same column region in SELECT and GROUP BY for correct aggregation.