SQL Greater Than or Equal To Operator

The SQL >= (Greater Than or Equal To) operator is used to filter records where a column value is either greater than or exactly equal to a specified value. It is commonly used in the WHERE clause to retrieve data that meets or exceeds a certain threshold.

In this tutorial, we will cover the syntax and examples of using the >= operator in SQL queries.


Syntax of SQL >= Operator

The basic syntax for using the >= operator in an SQL WHERE clause is:

</>
Copy
SELECT column1, column2, ...
FROM table_name
WHERE column_name >= value;

Explanation:

  • SELECT: Specifies the columns to retrieve.
  • FROM: Defines the table from which data is fetched.
  • WHERE: Filters the records based on a condition.
  • >=: Ensures only records where the column value is greater than or equal to the specified value are returned.

Step-by-Step Examples Using SQL >= Operator

1. Selecting Students Aged 18 or Older

Let’s create a students table to demonstrate the >= operator:

</>
Copy
CREATE TABLE students (
    id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(50),
    age INT,
    grade VARCHAR(10)
);

Insert some sample data:

</>
Copy
INSERT INTO students (name, age, grade)
VALUES 
('Arjun', 17, '11th'),
('Ram', 18, '12th'),
('John', 19, '12th'),
('Priya', 16, '10th');

Now, let’s use the >= operator to select students who are 18 years old or older:

</>
Copy
SELECT * FROM students
WHERE age >= 18;

Explanation:

  • This query selects students whose age is greater than or equal to 18.
  • The result will include Ram (18) and John (19), but exclude Arjun (17) and Priya (16).

2. Selecting Employees with Salary >= 50000

Consider an employees table storing salary information:

</>
Copy
CREATE TABLE employees (
    id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(50),
    salary DECIMAL(10,2),
    department VARCHAR(50)
);

Insert some sample records:

</>
Copy
INSERT INTO employees (name, salary, department)
VALUES 
('Arjun', 45000, 'Finance'),
('Ram', 55000, 'HR'),
('John', 60000, 'IT'),
('Priya', 50000, 'Marketing');

Now, let’s retrieve employees earning 50000 or more:

</>
Copy
SELECT * FROM employees
WHERE salary >= 50000;

Explanation:

  • The query retrieves employees with salaries greater than or equal to 50000.
  • The result will include Ram (55000), John (60000), and Priya (50000), but exclude Arjun (45000).

Conclusion

In this SQL Greater Than or Equal To Operator tutorial, we covered:

  1. The syntax of the >= operator.
  2. Example queries selecting students of age 18 or older.
  3. Example queries retrieving employees earning 50000 or more.