GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • SQL
  • Projects
  • Interview Questions
  • Quiz
  • DBMS
  • PostgreSQL
  • Django
  • ReactJS
  • Vue.js
  • AngularJS
  • API
  • REST API
  • SQL3 min read
  • Data Types3 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — SQL Operators - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • SQL
  • Projects
  • Interview Questions
  • Quiz
  • DBMS
  • PostgreSQL
  • Django
  • ReactJS
  • Vue.js
  • AngularJS
  • API
  • REST API

SQL Operators

Last Updated : 29 Aug, 2026

SQL operators are symbols or keywords used to perform operations on data in SQL queries.

  • Perform operations like calculations, comparisons and logical checks.
  • Enable filtering, calculating and updating data in databases.
  • Essential for query optimization and accurate data management.
sql_operators
SQL Operators

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations on numeric values.

OperatorDescriptionExample
+Addition10 + 20
-Subtraction20 - 10
*Multiplication10 * 20
/Division20 / 10
%Modulus10 % 3

Example

SELECT
10 + 20 AS addition,
20 - 10 AS subtraction,
10 * 20 AS multiplication,
20 / 10 AS division,
10 % 3 AS modulus;

Output:

Screenshot-2026-08-27-111344
  • Arithmetic operators are useful for calculations such as salaries, prices, quantities, discounts and totals.

Comparison Operators

Comparison operators are used to compare two values or expressions. They are commonly used with the WHERE clause to filter records.

OperatorDescriptionExample
=Equal to10 = 10
!=Not equal to10 != 20
<>Not equal to10 <> 20
>Greater than20 > 10
<Less than10 < 20
>=Greater than or equal to20 >= 20
<=Less than or equal to10 <= 20

Example:

Consider an employees table:

Screenshot-2026-08-27-111535

The following query uses the greater-than operator:

SELECT
name,
salary
FROM employees
WHERE salary > 50000;

Output:

Screenshot-2026-08-27-111750

The query returns employees whose salary is greater than 50000.

Logical Operators

Logical operators are used to combine or modify multiple conditions.

OperatorDescription
ANDReturns TRUE when all conditions are true
ORReturns TRUE when at least one condition is true
NOTReverses the result of a condition

Example:

SELECT
name,
salary
FROM employees
WHERE salary > 50000
AND salary < 70000;

Output:

Screenshot-2026-08-27-111823
  • Both conditions must be satisfied for a row to be returned.

Example:

SELECT
name,
salary
FROM employees
WHERE salary = 40000
OR salary = 70000;

Output:

Screenshot-2026-08-27-112203
  • The OR operator returns rows that satisfy at least one condition.

Special Operators

SQL also provides operators for specific filtering and conditional operations.

BETWEEN

The BETWEEN operator checks whether a value falls within a specified range.

SELECT
name,
salary
FROM employees
WHERE salary BETWEEN 40000 AND 60000;

Output:

Screenshot-2026-08-27-112203
  • BETWEEN includes both boundary values.

IN

The IN operator checks whether a value matches any value in a specified list.

SELECT
name,
salary
FROM employees
WHERE salary IN (40000, 70000);

Output:

Screenshot-2026-08-27-112203

LIKE

The LIKE operator is used to search for a specific pattern in text values.

SELECT
name
FROM employees
WHERE name LIKE 'A%';

Output:

Screenshot-2026-08-27-112703
  • Here, % represents zero or more characters.

EXISTS

The EXISTS operator checks whether a subquery returns at least one row.

SELECT *
FROM employees e
WHERE EXISTS (
SELECT 1
FROM employees
WHERE salary > 50000
);

Output:

Screenshot-2026-08-27-111535
  • The subquery checks whether at least one employee has a salary above 50000. If so, EXISTS returns TRUE and the query returns all employees.

IS NULL

The IS NULL operator checks whether a value is NULL.

SELECT
name
FROM employees
WHERE manager_id IS NULL;

Output:

Screenshot-2026-08-27-113150
  • This query returns employees whose manager_id is NULL, meaning they do not have a manager assigned.

IS NOT NULL

The IS NOT NULL operator checks whether a value is not NULL.

SELECT
name
FROM employees
WHERE manager_id IS NOT NULL;

Output:

Screenshot-2026-08-27-111535

Bitwise Operators

SQL bitwise operators are used to perform operations on the individual bits of integer values. These operators work on the binary representation of numbers and are commonly used with flags, permissions and status values.

Types of Bitwise Operators

OperatorDescription
&Bitwise AND
`Bitwise OR
^Bitwise XOR
~Bitwise NOT
<<Left Shift
>>Right Shift

Note: Bitwise operator support and syntax may vary between SQL database systems.

Example

Consider the following values:

SELECT
12 & 10 AS bitwise_and,
12 | 10 AS bitwise_or,
12 ^ 10 AS bitwise_xor,
~12 AS bitwise_not,
12 << 2 AS left_shift,
12 >> 2 AS right_shift;

Output

For a database system that supports these operators:

Screenshot-2026-08-27-114236

A bitwise AND operation can be used to check whether a particular permission is enabled:

SELECT
employee_id,
name,
permissions
FROM employees
WHERE permissions & 1 = 1;

Output:

Screenshot-2026-08-27-114528

The & operator checks whether the least significant bit of permissions is set to 1. This can be used to determine whether a particular permission flag is enabled

Compound Operators

Compound operators combine an arithmetic or bitwise operation with an assignment operation. They allow a value to be modified and assigned back to the same variable or column in a single statement.

Types of Compound Operators

OperatorDescription
+=Adds a value and assigns the result
-=Subtracts a value and assigns the result
*=Multiplies a value and assigns the result
/=Divides a value and assigns the result
%=Calculates modulus and assigns the result
&=Performs bitwise AND and assigns the result
`=`
^=Performs bitwise XOR and assigns the result

Example

The += operator can be used to increase the salary of all employees by 5000.

UPDATE employees
SET salary += 5000;

Output:

Screenshot-2026-08-27-114928
Comment

Explore

    Basics
    • SQL3 min read
    • Data Types3 min read
    • Operators4 min read
    • Commands5 min read
    • Database Operations2 min read
    • CREATE TABLE2 min read
    Queries & Operations
    • SELECT Query2 min read
    • INSERT INTO3 min read
    • UPDATE2 min read
    • DELETE2 min read
    • WHERE2 min read
    • Aliases2 min read
    Joins & Functions
    • Joins3 min read
    • CROSS JOIN1 min read
    • Date Functions2 min read
    • String functions4 min read
    Data Constraints & Aggregate Functions
    • NOT NULL Constraint3 min read
    • PRIMARY KEY3 min read
    • Count()4 min read
    • SUM()2 min read
    • MAX()3 min read
    • AVG()2 min read
    Advanced SQL Topics
    • Subquery4 min read
    • Window Functions4 min read
    • Stored Procedures3 min read
    • Triggers4 min read
    • Performance Tuning4 min read
    • TRANSACTIONS4 min read
    Database Design & Security
    • ER Model9 min read
    • Normalization2 min read
    • Keys in Relational Model7 min read
    • SQL Injection10 min read
    • Data Encryption3 min read
    • SQL Backup4 min read
    • ORM in DBMS5 min read
    Courses
    • Placement 360 Course2 min read
    • Data Science 360 Course2 min read
    • MERN Full Stack Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.