Loading
SQL Comparison Operator
SQL Comparison Operators are used to compare two values, columns, or expressions in a database. They are mostly used with the WHERE clause to filter rows based on specific conditions.



What Are Comparison Operators?

  • Used in SQL queries to compare values in columns.
  • Return results that match, differ, or are greater/less than a given value.
  • Widely used in SELECT, UPDATE, and DELETE statements with the WHERE clause.



List of SQL Comparison Operators

OperatorDescription
=Equal to - returns rows equal to the given value
>Greater than - returns rows with values greater
<Less than - returns rows with values less
>=Greater than or equal to - returns rows greater than or equal to the value
<=Less than or equal to - returns rows less than or equal to the value
!= or <>Not equal to - returns rows not matching the value



Student Table

Header 1Header 2Header 3Header 4
1Aman8692
2Sushant9191
3Soumya9898



Example: Using equal to ( = )

SELECT * FROM student WHERE physics = 86;

Output:

IDNamePhysicsChemistry
1Aman8692

Explanation: This query selects the row(s) where the value in the Physics column is exactly equal to 86.



More Use Cases


> Greater Than

SELECT * FROM student WHERE chemistry > 91;

Returns students with chemistry marks grater than 91.



!= Not Equal

SELECT * FROM student WHERE name != 'Aman';

Returns all students except Aman.



Key Point

  • Comparison operators return TRUE or FALSE for each row, determining whether to include it in the result.
  • Can be used to compare columns, values, or expressions.
  • Can be combined with logical operators (AND, OR, NOT) for advanced filtering.