In SQL, can the BETWEEN keyword be used in a WHERE clause to select rows whose column values fall within an inclusive range (lower and upper bounds included)?

Difficulty: Easy

Correct Answer: Applies — BETWEEN selects values within an inclusive range

Explanation:


Introduction / Context:
This item tests knowledge of basic SQL filtering syntax, specifically how the BETWEEN operator works inside a WHERE clause to capture values in a continuous interval.



Given Data / Assumptions:

  • Standard SQL WHERE clause is used for row filtering.
  • BETWEEN has the form: column BETWEEN lower AND upper.
  • Lower and upper endpoints are included.
  • BETWEEN works for comparable types such as numbers, dates/timestamps, and text (when collation/ordering applies).



Concept / Approach:
BETWEEN is syntactic sugar equivalent to column >= lower AND column <= upper. With dates, it selects rows whose date is on or after the lower bound and on or before the upper bound. With strings, inclusion follows the database’s collation order.



Step-by-Step Solution:
Recognize that a “range of values” means contiguous values between two bounds.Recall the equivalence: a BETWEEN b AND c ⇔ a >= b AND a <= c.Note inclusivity at both ends.Conclude the statement is accurate.



Verification / Alternative check:
Write quick examples, e.g., WHERE amount BETWEEN 100 AND 200 or WHERE order_date BETWEEN DATE '2023-01-01' AND DATE '2023-01-31'; both include boundary values 100, 200 and the first and last day.



Why Other Options Are Wrong:
Exclusive bounds are incorrect; BETWEEN is inclusive. It is valid in WHERE as well as HAVING, and it applies to multiple data types, not only character data.



Common Pitfalls:
For timestamps, upper bounds like '2023-01-31' may exclude times later that day; use an upper bound of the next day or an explicit < condition. For strings, understand collation implications.



Final Answer:
Applies — BETWEEN selects values within an inclusive range

Discussion & Comments

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