PostgreSQL – Greater Than (>) Operator
The greater-than operator (>
) is a comparison operator in postgresql used to check if one value is greater than another value. It’s often used in WHERE
clauses to filter rows based on a specific condition involving numerical or string values.
The syntax for using the greater-than operator is as follows:
SELECT columns FROM table_name WHERE column_name > value;
Here’s an example of using the greater-than operator:
SELECT product_name, price FROM products WHERE price > 100;
In this example, the query retrieves the product name and price for products with a price greater than $100.
The greater-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 after January 1, 2023.
You can also combine the greater-than operator with other operators and conditions in more complex queries. For example:
SELECT employee_name, salary FROM employees WHERE department = 'Sales' AND salary > 50000;
In this example, the query retrieves the employee name and salary for employees in the ‘Sales’ department with a salary greater than $50,000.
The greater-than operator is a fundamental tool for making comparisons in SQL queries and is widely used to filter and retrieve specific data based on numerical, string, or date values.