BETWEEN / IN / LIKE
Feb 23, 2026
·
5
min read
Category: Comparison Operators
Platform Support:
✅ Snowflake | ✅ BigQuery | ✅ Databricks
Description
Comparison operators for filtering data. BETWEEN checks if a value is within a range (inclusive), IN checks if a value matches any in a list, and LIKE performs pattern matching on strings. Essential for WHERE clause filtering and conditional logic.
Syntax
BETWEEN:
IN:
LIKE:
Platform-Specific Notes
All Platforms:
Standard SQL operators
Work identically across platforms
Can be combined with NOT
Case-sensitive by default (use ILIKE for case-insensitive in Snowflake)
Snowflake:
ILIKE for case-insensitive pattern matching
RLIKE for regex matching
BigQuery:
Case-insensitive by default for some collations
Use REGEXP_CONTAINS for regex
Databricks:
Standard SQL LIKE
RLIKE for regex patterns
Example 1: BETWEEN - Numeric and Date Ranges
All Platforms:
Sample Data (products table):
product_id | product_name | price | category |
|---|---|---|---|
1 | Mouse | 29.99 | Electronics |
2 | Keyboard | 89.99 | Electronics |
3 | Monitor | 299.99 | Electronics |
4 | Desk | 199.99 | Furniture |
5 | Chair | 149.99 | Furniture |
Result (price BETWEEN 50 AND 150):
product_name | price | category |
|---|---|---|
Keyboard | 89.99 | Electronics |
Chair | 149.99 | Furniture |
Example 2: IN - List of Values
All Platforms:
Sample Data (customers table):
customer_id | customer_name | country | status |
|---|---|---|---|
1 | John Smith | USA | Active |
2 | Maria Garcia | Spain | Active |
3 | Bob Johnson | Canada | Premium |
4 | Sarah Lee | USA | Inactive |
5 | Carlos Ruiz | Mexico | Active |
Result (country IN ('USA', 'Canada', 'Mexico') AND status IN ('Active', 'Premium')):
customer_name | country | status |
|---|---|---|
John Smith | USA | Active |
Bob Johnson | Canada | Premium |
Carlos Ruiz | Mexico | Active |
Example 3: LIKE - Pattern Matching
All Platforms:
Sample Data (customers table):
customer_id | customer_name | |
|---|---|---|
1 | John Smith | |
2 | Johnny Doe | |
3 | Maria Garcia | |
4 | Sarah Johnson |
Result (email LIKE 'john%'):
Result (email LIKE '%@gmail.com'):
Example 4: Case-Insensitive Matching
Snowflake (ILIKE):
BigQuery / Databricks:
Example 5: Combining Operators
All Platforms:
Sample Data:
order_id | customer_name | order_date | total | status |
|---|---|---|---|---|
101 | John Smith | 2024-01-15 | 250.00 | Shipped |
102 | Maria Garcia | 2024-01-20 | 450.00 | Delivered |
103 | James Brown | 2024-02-10 | 150.00 | Delivered |
104 | Jane Doe | 2024-02-15 | 50.00 | Shipped |
105 | Jake Wilson | 2024-03-01 | 2000.00 | Pending |
Result:
order_id | customer_name | order_date | total | status |
|---|---|---|---|---|
103 | James Brown | 2024-02-10 | 150.00 | Delivered |
101 | John Smith | 2024-01-15 | 250.00 | Shipped |
Example 6: LIKE Escape Characters
All Platforms:
BETWEEN vs Comparison Operators
Expression | Equivalent | Notes |
|---|---|---|
|
| Inclusive of both bounds |
|
| Exclusive of bounds |
IN vs OR
Expression | Equivalent | Performance |
|---|---|---|
|
| IN is cleaner and often faster |
| Subquery join | Can use indexes |
LIKE Pattern Examples
Pattern | Matches | Example |
|---|---|---|
| Starts with A | Apple, Ant |
| Ends with z | Quiz, Jazz |
| Contains 'or' | Word, Store |
| 3 chars ending in 'at' | Cat, Bat, Hat |
| Starts with digit | 1st, 5pm |
| Ends with 20XX | 2023, 2024 |
NULL Handling
Important: NULL values require special handling
Performance Considerations
BETWEEN:
Fast: Uses indexes efficiently
Tip: Index columns used in BETWEEN
IN:
Small lists (<100 values): Very fast
Large lists: Consider temp table + JOIN
Subqueries: Optimized by query planner
Avoid: NOT IN with NULLs
LIKE:
Leading wildcard (
'%abc'): Cannot use index (slow)Trailing wildcard (
'abc%'): Can use index (fast)Consider: Full-text search for complex patterns
Common Use Cases
BETWEEN:
Date ranges: Monthly/quarterly reports
Price ranges: Product filtering
Age ranges: Demographics
Score ranges: Grade boundaries
IN:
Category filtering: Multiple selections
Whitelist/blacklist: Allowed/blocked values
Subquery results: Dynamic filtering
Multi-value parameters: User selections
LIKE:
Search functionality: Name/description search
Email validation: Domain checks
Code matching: Product SKUs
Partial matching: Auto-complete
Best Practices
Use BETWEEN for ranges: Cleaner than >= AND <=
Prefer IN over multiple ORs: More readable
Avoid leading wildcards in LIKE: Performance impact
Handle NULLs explicitly: Especially with NOT IN
Use ILIKE sparingly: Case-insensitive search is slower
Consider indexes: For frequently filtered columns
Validate input: Prevent SQL injection with LIKE
Test with NULLs: Verify behavior with NULL values





