0
0
PostgreSQLquery~5 mins

BETWEEN for range filtering in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL BETWEEN operator do?
The BETWEEN operator filters rows where a column's value is within a specified range, including the start and end values.
Click to reveal answer
beginner
Write a SQL query using BETWEEN to find all orders with amounts between 100 and 500.
SELECT * FROM orders WHERE amount BETWEEN 100 AND 500;
Click to reveal answer
beginner
Does BETWEEN include the boundary values in the range?
Yes, BETWEEN includes both the start and end values in the range check.
Click to reveal answer
intermediate
How is BETWEEN different from using >= and <= operators?
BETWEEN is a shorthand for using >= and <= together. For example, 'x BETWEEN a AND b' is the same as 'x >= a AND x <= b'.
Click to reveal answer
beginner
Can BETWEEN be used with dates in PostgreSQL?
Yes, BETWEEN works with dates to filter rows within a date range, including the start and end dates.
Click to reveal answer
Which of the following queries correctly finds products priced between 50 and 100?
ASELECT * FROM products WHERE price BETWEEN 50 AND 100;
BSELECT * FROM products WHERE price > 50 AND price < 100;
CSELECT * FROM products WHERE price = 50 OR price = 100;
DSELECT * FROM products WHERE price >= 50 OR price <= 100;
Does the BETWEEN operator include the boundary values in its range?
AIt includes only the lower boundary.
BNo, it excludes both boundaries.
CYes, it includes both boundaries.
DIt includes only the upper boundary.
Which is equivalent to 'salary BETWEEN 3000 AND 7000'?
Asalary >= 3000 AND salary <= 7000
Bsalary = 3000 OR salary = 7000
Csalary > 3000 OR salary < 7000
Dsalary > 3000 AND salary < 7000
Can BETWEEN be used to filter date columns in PostgreSQL?
AOnly with special date functions.
BNo, BETWEEN only works with numbers.
COnly if dates are converted to strings.
DYes, it works with dates.
What will this query return? SELECT * FROM sales WHERE sale_date BETWEEN '2024-01-01' AND '2024-01-31';
ASales only on January 1 and January 31, 2024.
BSales from January 1 to January 31, 2024, inclusive.
CSales before January 1, 2024.
DSales after January 31, 2024.
Explain how the BETWEEN operator works for filtering numeric ranges in SQL.
Think about how you check if a number is between two others.
You got /4 concepts.
    Describe how you would use BETWEEN to filter rows by date in PostgreSQL.
    Dates can be compared like numbers in SQL.
    You got /4 concepts.