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_nameWHERE 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.

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:

2. Greater than (>) Operator: It returns the rows which have the value of the attribute greater than the given value.
Query:
SELECT *FROM mathsWHERE marks > 60;
Output:

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:

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 mathsWHERE marks >= 80;
Output:

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 mathsWHERE marks <= 30;
Output:

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:
