Back to SQL Course - Back to Operators
Compares two different data returning a boolean value (TRUE or FALSE), checking if equal, greater or lesser.
Checks if the values of two operands are equal or not, returning a boolean (TRUE, FALSE).
WHERE OPERAND1 = OPERAND2;
-- 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;
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.
-- 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;
Checks if the operand on the left is greater than the operand on the right, returning a boolean (TRUE, FALSE).
WHERE OPERAND1 > OPERAND2;
-- 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;
Checks if the operand on the left is less than the operand on the right, returning a boolean (TRUE, FALSE).
WHERE OPERAND1 < OPERAND2;
-- 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;
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;
-- 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;
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;
-- 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.