PostgreSQL – Less Than (<) Operator

The less-than operator (<) is a comparison operator used to check if one value is less than another value. It’s commonly used in WHERE clauses to filter rows based on a specific condition involving numerical or string values.

The syntax for using the less-than operator is as follows:

SELECT columns FROM table_name WHERE column_name < value;

Here’s an example of using the less-than operator:

SELECT product_name, price FROM products WHERE price < 50;

In this example, the query retrieves the product name and price for products with a price less than $50.

The less-than operator can also be used with date or timestamp values:

SELECT customer_name, order_date FROM orders WHERE order_date < '2023-01-01';

In this example, the query retrieves the customer name and order date for orders placed before January 1, 2023.

You can also combine the less-than operator with other operators and conditions for more complex queries. For instance:

SELECT employee_name, salary FROM employees WHERE department = 'IT' AND salary < 60000;

In this example, the query retrieves the employee name and salary for employees in the ‘IT’ department with a salary less than $60,000.

The less-than operator is a foundational element for making comparisons in SQL queries, helping you filter and retrieve specific data based on numerical, string, or date values.

Similar Posts