Manuel Gentile

Back to SQL Course - Back to Operators

Comparison Operators

Compares two different data returning a boolean value (TRUE or FALSE), checking if equal, greater or lesser.

Equal

Checks if the values of two operands are equal or not, returning a boolean (TRUE, FALSE).

WHERE OPERAND1 = OPERAND2;

Equal Example

-- Simple condition, returns TRUE
SELECT * FROM employee WHERE 1 = 1;
-- Condition between a column and a value
SELECT * FROM employee WHERE last_name = 'Gentile';
-- Condition between two columns of a table
SELECT * FROM employee WHERE last_name = first_name;

Not Equal

Checks if the values of two operands are equal or not, returning a boolean (TRUE, FALSE).

WHERE OPERAND1 != OPERAND2;
WHERE OPERAND1 <> OPERAND2;

You can use the two symbols interchangeably.

Not Equal Example

-- Simple condition, returns FALSE
SELECT * FROM employee WHERE 1 <> 1;
-- Condition between a column and a value
SELECT * FROM employee WHERE last_name != 'Gentile';
-- Condition between two columns of a table
SELECT * FROM employee WHERE last_name <> first_name;

Greater

Checks if the operand on the left is greater than the operand on the right, returning a boolean (TRUE, FALSE).

WHERE OPERAND1 > OPERAND2;

Greater Example

-- Simple condition, returns FALSE
SELECT * FROM employee WHERE 1 > 2;
-- Condition between a column and a value
SELECT * FROM employee WHERE age > 21;
-- Condition between two columns of a table
SELECT * FROM products WHERE max_value > min_value;

Less

Checks if the operand on the left is less than the operand on the right, returning a boolean (TRUE, FALSE).

WHERE OPERAND1 < OPERAND2;

Less Example

-- Simple condition, returns TRUE
SELECT * FROM employee WHERE 1 < 2;
-- Condition between a column and a value
SELECT * FROM employee WHERE age < 18;
-- Condition between two columns of a table
SELECT * FROM products WHERE max_value < min_value;

Greater Or Equal

Checks if the operand on the left is greater than or equal to the operand on the right, returning a boolean (TRUE, FALSE).

WHERE OPERAND1 >= OPERAND2;

Greater Example

-- Simple condition, returns FALSE
SELECT * FROM employee WHERE 1 >= 2;
-- Condition between a column and a value
SELECT * FROM employee WHERE age >= 21;
-- Condition between two columns of a table
SELECT * FROM products WHERE max_value >= min_value;

Less Or Equal

Checks if the operand on the left is less than or equal to the operand on the right, returning a boolean (TRUE, FALSE).

WHERE OPERAND1 <= OPERAND2;

Less Example

-- Simple condition, returns TRUE
SELECT * FROM employee WHERE 1 <= 2;
-- Condition between a column and a value
SELECT * FROM employee WHERE age <= 18;
-- Condition between two columns of a table
SELECT * FROM products WHERE max_value <= min_value;

Back to SQL Course - Back to Operators


Let’s connect

If you want to learn more about the topic, connect or send me a DM.

Website