sqlbeginner10 minutes

Refactor to Optimize a Basic Employee Salary Query

Improve the given SQL query that retrieves employee names and salaries, by refactoring it to be more efficient while keeping the result unchanged.

Challenge prompt

You have the following SQL query that selects employee names and their salaries from the Employees table, but it includes redundant operations that can be optimized. Refactor the query to produce the same output but with simplified and more efficient SQL syntax.

Guidance

  • Look for unnecessary subqueries or repeated table scans.
  • Try to simplify logic like filtering or selecting columns directly.

Hints

  • Avoid using a subquery if the same results can be achieved with a simpler SELECT.
  • Check if filtering conditions can be applied directly without nested queries.

Starter code

SELECT name, salary FROM (SELECT * FROM Employees) AS emp WHERE salary > 30000;

Expected output

A list of employee names and their salaries where salary is greater than 30000.

Core concepts

SELECTWHERE clausesubqueriesquery optimization

Challenge a Friend

Send this duel to someone else and see if they can solve it.