Difficulty: Easy
Correct Answer: Incorrect
Explanation:
Introduction / Context:
SQL predicates often involve multiple conditions. The question asserts that with three or more AND/OR terms, it is typically easier to use NOT and NOT IN. This probes best practices for clarity and correctness in boolean logic.
Given Data / Assumptions:
Concept / Approach:
While NOT and NOT IN are valid, they are not inherently simpler. Good practice is to write clear, positive logic with explicit parentheses to control evaluation and avoid precedence surprises. Use IN/NOT IN for set membership when it simplifies expression, but do not default to negation for complexity. For example, WHERE (status IN ('NEW','PENDING')) AND (amount >= 100) OR (vip_flag = true) may be clearer than a negated equivalent. Parentheses communicate intent and prevent logic bugs.
Step-by-Step Solution:
Verification / Alternative check:
Create a small truth table to compare the original AND/OR logic with a proposed NOT/NOT IN rewrite; ensure equivalence and prefer the clearer version.
Why Other Options Are Wrong:
Common Pitfalls:
Relying on default precedence (AND before OR) without parentheses, and misusing NOT IN with NULLs (which can yield unexpected filtering due to three-valued logic). Prefer explicit parentheses and consider IS DISTINCT FROM where supported.
Final Answer:
Incorrect
Discussion & Comments