Loading

SQL Comparison Operators

  • SQL Comparison operator is used to compare the two operands or two data values present in the database tables.
  • The comparison operators can also compare one expression to the other.
  • The SQL comparison operators are used with the WHERE clause.

The various SQL comparison operators are:

OperatorDescription
=

The Equal operator is used to show data

 that matches with the provided value in the query.

>

The Greater Than is used to show data

 that are greater than the provided value in the query.

<

The Lesser Than is used to show data

 that are lesser than the provided value in the query.

>=

The Greater Than Equals to an operator is used

 to show data that are greater than and equal to the provided value

<=

The Lesser Than Equals to an operator is used

 to show data that are lesser than and equal to the provided value

!=

The Not Equal operator is used to show

 data that do not match with the provided value in the query


Example:

Suppose we have a database of students. The student table has 4 columns namely student ID, Name, physics(marks in physics), and Chemistry(marks in chemistry)

ID

Name

Physics

Chemistry

1

Aman

86

92

2

Sushant

91

91

3

Soumya

98

98


Let us perform some comparison operations using comparison operators:

SELECT *
FROM student
WHERE physics = 86;

Output:

ID

Name

Physics

Chemistry

1

Aman

86

92

  • In this example, we fetch the student detail whose physics mark is 86