SQL Comparison Operators
What are the SQL Comparison Operators?
Comparison Operators, sometimes referred to as relational or boolean operators, compare values in a database and determine if they are equal (=), not equal (!=, <>), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=). They are used in conditions within SQL statements, such as in the WHERE clause.
The following are code examples of commonly used comparison operators in SQL:
Equal =
For example, in a SELECT statement, a WHERE clause could use the = operator to return rows where the value of a column is equal to a specified value, such as:
SELECT column1, column2
FROM table
WHERE column2 = 'value';
Not Equal != or <>
For example, in a SELECT statement, a WHERE clause could use the != or <> operator to return rows where the value of a column is not equal to a specified value, such as:
SELECT column1, column2
FROM table
WHERE column2 != 'value';
Greater than >
For example, in a SELECT statement, a WHERE clause could use the > operator to return rows where the value of a column is greater than a specified value, such as:
SELECT column1, column2
FROM table
WHERE column2 > 'value';
Less than <
For example, in a SELECT statement, a WHERE clause could use the < operator to return rows where the value of a column is less than a specified value, such as:
SELECT column1, column2
FROM table
WHERE column2 < 'value';
Greater than or equal to >=
For example, in a SELECT statement, a WHERE clause could use the >= operator to return rows where the value of a column is greater than or equal to a specified value, such as:
SELECT column1, column2
FROM table
WHERE column2 >= 'value';
Less than or equal to <=
For example, in a SELECT statement, a WHERE clause could use the <= operator to return rows where the value of a column is less than or equal a specified value, such as:
SELECT column1, column2
FROM table
WHERE column2 <= 'value';