sqlbeginner10 minutes

Refactor SQL Query to Optimize SELECT and WHERE Clauses

Improve a given SQL query by refactoring it for better readability and performance while maintaining the same result. This challenge focuses on optimizing basic SELECT and WHERE statements for beginners.

Challenge prompt

You are given a SQL query that retrieves all employees from the 'employees' table who are in department 'Sales' and have a salary greater than 50000. The query currently uses redundant conditions and inefficient WHERE clause structure. Refactor the query to make it simpler and potentially more efficient without changing its output.

Guidance

  • Identify any redundant or unnecessary parts of the WHERE clause.
  • Combine conditions where possible to simplify logical expressions.

Hints

  • Use AND operator effectively to consolidate conditions.
  • Avoid repeating the same filter conditions in multiple places.

Starter code

SELECT * FROM employees WHERE department = 'Sales' AND salary > 50000 AND department = 'Sales';

Expected output

All rows from 'employees' where department is 'Sales' and salary is greater than 50000, with no duplicates or redundant filters.

Core concepts

Basic SQL SELECTWHERE clause optimization

Challenge a Friend

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