GREATER THAN OR EQUAL TO Operator (>=) - SQL


Overview


The Greater than or equal to operator (>=) is used to compare two expressions. It returns true if the left expression is greater than or equal to the right expression. It can be used in SQL queries to filter records based on a comparison.

Syntax:

SELECT number1 >= number2

number1 >= number2 checks if the value number1 is greater than or equal to number2.

Sample Data:

first_name vacation_days
Frank 5
Jane 2
Ashley 3
Glenn -3
Kelly 2
Richard -7
George 2
Kyle 1
James -2
Gustavo -10

Example: Hard-coded values (TRUE) value


In this example, the Greater than or equal to operator is used to evaluate whether the 10 >= 5 is true. Since 10 is greater than or equal to 5, the query will return an output of 1, indicating that it is true.

Example:

SELECT 10 >= 5


Example: Hard-coded values (FALSE) value


In this example, the Greater than or equal to operator is used to evaluate whether the 2 >= 5 is true. Since 2 is not greater than or equal to 5, the query will return an output of 0, indicating that it is false.

Example:

SELECT 2 >= 5


Example: Query without the WHERE Statement


In this example, we are returning the vacation_days column and a column that checks if each value in the vacation_days column is greater than or equal to 2. The final output is the original vacation_days column alongside the column checking whether it’s greater than or equal to 2.

Example:

SELECT vacation_days, vacation_days >= 2
FROM company.employees


Example: Query with the WHERE Statement


In this example, we are filtering for rows in the department_id column using the greater than or equal to operator, we only want department_id greater than or equal to 3. We are also returning the vacation_days column and a column that checks if each value in the vacation_days column is greater than or equal to 2. The final output is the original vacation_days column alongside the column checking whether it’s greater than or equal to 2.

Example:

SELECT vacation_days, vacation_days >= 2
FROM company.employees
WHERE department_id >= 3