A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/postgresql/postgresql-or-operator/ below:

PostgreSQL OR Operator - GeeksforGeeks

PostgreSQL OR Operator

Last Updated : 23 Jul, 2025

PostgreSQL OR operator is a logical operator that lets you connect several conditions in the WHERE clause to get the rows that are related to at least one of the specified ones. It returns true if any of the given conditions found by the 'OR' operator has the truth as its result.

Let us get a better understanding of the PostgreSQL OR operator from this article.

Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

Here, 'condition1', 'condition2', etc., are the conditions you want to evaluate using the OR operator. You can have as many conditions as needed, separated by OR.

PostgreSQL OR Operator Examples

Let us take a look at some of the examples of OR Operator in PostgreSQL to better understand the concept.

First, let's create a table named as 'employees' in PostgreSQL insert some data into it and then perform some queries using the OR operator.

PostgreSQL
CREATE TABLE employees (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100),
    department VARCHAR(100),
    salary NUMERIC(10, 2)
);
INSERT INTO employees (name, department, salary)
VALUES
    ('Minal Pandey', 'Sales', 60000),
    ('Vivek Sharma', 'Marketing', 55000),
    ('Priyanshi Sharma', 'Sales', 48000),
    ('Vardhana Sharma', 'Engineering', 70000);
SELECT * FROM employees;
Employees Table Example 1: Retrieve Employees in Sales Departments or with salaries higher than 55000.

The query below selects all of the "employees" table's items if the department is 'Sales' or if the salary is more than 55000.

Query:

SELECT * FROM employees
WHERE department = 'Sales' OR  salary > 55000

Output:

Example 1

Explanation: You can see that query returns up every row in the "employees" table, whether the department name is "Sales" or if the salary is more than 55000.

Example 2: Retrieving employees in Sales or Marketing Departments or with salaries higher than 55000.

This query selects the names of employees from the "employees" table where the department is either 'Sales' or 'Marketing', or where the salary is greater than 55000.

Query:

SELECT name
FROM employees
WHERE department = 'Sales' OR department = 'Marketing' OR salary > 55000;

Output:

Example 2

Explanation: You can see that the query returned the names of employees who work in the 'Sales' or 'Marketing' department, or whose salary is greater than 55000.

Example 3: Retrieve Employees in Marketing Departments or with salaries higher than 55000.

The query below selects all of "employees" table's items if the department is 'Marketing' or if the salary is more than 55000.

Query:

SELECT * FROM employees
WHERE department = 'Marketing' OR salary > 55000;

Output:

Example 3

Explanation: You can see that the query returned all information about employees who work in the 'Marketing' department or have a salary greater than 55000.

Important Points About PostgreSQL OR Operator


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4