SQL Comparison Operators - GeeksforGeeks

SQL Comparison Operators

Last Updated : 28 Oct, 2026

SQL Comparison Operators are used to compare two values and filter the result set based on a specific condition.

  • Used in the WHERE clause to filter records based on conditions
  • Help check for equality, range or inequality

Common Comparison Operators

  • = : Matches records with the same value.
  • != : Filters out records with a specified value.
  • >= : Finds values that meet or exceed a given value.
  • < : Selects values below a specified value.
  • > : Retrieves values above a given value.
  • <= : Includes values that do not exceed a specified value.

Syntax

SELECT *
FROM table_name
WHERE column_name comparison_operator value;
  • table_name: The name of the table from which data is retrieved.
  • column_name: Specifies the column whose values are compared.
  • comparison_operator and value: Define the condition used to filter records.

Example: First, we will create a demo SQL table named maths containing student details such as roll_number, s_name and marks, which we will use to demonstrate SQL comparison operators.

sql_comparison_operators

Examples

1. Equal to (=) Operator: It returns the rows which have the value of the attribute equal to the given value.

Query:

SELECT *
FROM maths
WHERE marks = 50;

Output:

sql_comparison_operators1

2. Greater than (>) Operator: It returns the rows which have the value of the attribute greater than the given value.

Query:

SELECT *
FROM maths
WHERE marks > 60;

Output:

sql_comparison_operators2

3. Less than (<) Operator: It returns the rows which have the value of the attribute lesser than the given value.

Query:

SELECT *
FROM maths
WHERE marks < 40;

Output:

sql_comparison_operators3

4. Greater than or equal to (>=) Operator: It returns the rows which have the value of the attribute greater or equal to the given value.

Query:

SELECT *
FROM maths
WHERE marks >= 80;

Output:

sql_comparison_operators4


5. Less than or equal to (<=) Operator: It returns the rows which have the value of the attribute less or equal to the given value.

Query:

SELECT *
FROM maths
WHERE marks <= 30;

Output:

sql_comparison_operators5


6. Not equal to (<>) Operator: It returns the rows which have the value of the attribute that is not equal to the given value.

Query:

SELECT *
FROM maths
WHERE marks <> 70;

Output:

sql_comparison_operators6
Comment