Junior — Middle
What limitations exist when using conditions in the WHERE clause in SQL?
sobes.tech AI
Answer from AI
The WHERE operator in SQL has the following restrictions:
- Conditions must return a boolean value (TRUE, FALSE, or UNKNOWN).
- Aggregate functions (e.g., SUM, COUNT) cannot be used directly in WHERE; for this, HAVING is used.
- Conditions cannot reference aliases defined in SELECT.
- WHERE filters rows before grouping and sorting.
- Some DBMS impose restrictions on the use of subqueries or functions in WHERE.
Example:
SELECT * FROM employees
WHERE salary > 50000 AND department_id = 3;