WHERE clause expressiveness: can a WHERE condition reference multiple values/columns and combine predicates (using AND/OR/IN), or is it restricted to a single value?

Difficulty: Easy

Correct Answer: Incorrect

Explanation:

Introduction / Context:The WHERE clause filters rows before projection and grouping. This question checks whether WHERE can express complex conditions or is limited to a single value test.

Given Data / Assumptions:

  • Standard SQL boolean operators are available: AND, OR, NOT.
  • Set membership and subqueries can be used (IN, EXISTS).
  • Predicates may involve multiple columns and expressions.

Concept / Approach:WHERE is fully expressive for row filtering: WHERE (status IN ('NEW','PENDING')) AND (amount > 100) AND (region = 'EMEA'). It can compare column-to-column, column-to-expression, and even include scalar subqueries. It is not restricted to a single value comparison. WHERE applies before GROUP BY; HAVING filters groups after aggregation.

Step-by-Step Solution:

List all business rules to filter rows.Translate each rule into a predicate.Combine predicates with AND/OR, and use parentheses for clarity.Use IN/EXISTS for set logic and subqueries when needed.

Verification / Alternative check:Compare counts when applying individual predicates versus the full combined WHERE to ensure logic matches requirements.

Why Other Options Are Wrong:

  • Limiting WHERE to a single value is incorrect.
  • Subqueries are optional; many cases use literals or joins.
  • HAVING is not required for multi-value filters; it is for post-aggregation filtering.
  • WHERE supports many data types and operators beyond numeric equality.

Common Pitfalls:Ambiguous logic from missing parentheses, and confusing WHERE vs. HAVING. Always test boundary conditions and NULL handling.

Final Answer:Incorrect

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion