Course contentsShow
← Data Science
Lesson 857 of 2,14522. SQL FoundationsFree lesson

Comparison Operators: Greater and Less Than

Apply >, <, >=, and <= to filter numeric and date values based on relational comparisons.

Comparison Operators: Greater and Less Than

You'll learn how to filter SQL query results using relational comparison operators to find rows where numeric or date values fall above or below specific thresholds.


Understanding Relational Comparisons

Just like in everyday decisions—"Is this price higher than my budget?" or "Did this event happen before the deadline?"—SQL lets you filter data based on whether values are greater or less than a specific benchmark.

SQL provides four relational comparison operators:

  • > — greater than
  • < — less than
  • >= — greater than or equal to
  • <= — less than or equal to

These work with numeric values (integers, decimals) and dates.


How They Work in Practice

Using these operators in a WHERE clause filters your results to only rows meeting the condition:

SELECT product_name, price
FROM products
WHERE price > 50;

This returns only products priced above $50.

For dates, the same logic applies:

SELECT order_id, order_date
FROM orders
WHERE order_date >= '2024-01-01';

This retrieves orders from January 1, 2024 onward.


Inclusive vs. Exclusive Boundaries

Think of > and < as exclusive boundaries—they don't include the exact value. The operators >= and <= are inclusive, meaning they include the boundary value itself.

  • price > 100 excludes products priced exactly $100
  • price >= 100 includes products priced exactly $100

Key Takeaway: Use >, <, >=, and <= in your WHERE clause to filter numeric and date columns based on whether values exceed, fall below, or meet specific thresholds—enabling powerful range-based data retrieval.