SQL Greater Than Operator

The SQL > (greater than) operator is used to compare two values. It returns TRUE when the left operand is greater than the right operand. This operator is commonly used in the WHERE clause to filter results based on numerical or date-based conditions.

In this tutorial, we will explore the SQL greater than operator with syntax and practical examples.


Syntax of SQL Greater Than Operator

The basic syntax of the SQL > operator in a 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 retrieved.
  • WHERE: Introduces the condition for filtering.
  • >: Ensures only rows where column_name is greater than the given value are included.

Step-by-Step Examples Using SQL Greater Than Operator

1 Filtering Students Older Than 18

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
);

Insert some sample data:

</>
Copy
INSERT INTO students (name, age)
VALUES 
('Arjun', 20),
('Ram', 18),
('John', 22),
('Priya', 17);

Now, we retrieve students older than 18:

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