SQL Less Than Operator
The SQL <
(Less Than) operator is used to compare values in a query. It returns true if the left operand is less than the right operand. This operator is commonly used in the WHERE
clause to filter records based on numerical or date values.
In this tutorial, we will explore the SQL <
operator, its syntax, and how to use it with examples.
Syntax of SQL Less Than Operator
The basic syntax of the SQL <
operator is:
SELECT column1, column2, ...
FROM table_name
WHERE column_name < value;
Explanation:
- SELECT: Specifies the columns to retrieve from the table.
- FROM: Defines the table from which to retrieve data.
- WHERE: Filters the records based on the condition.
- <: Ensures only records where
column_name
is less than the specifiedvalue
are included.
Step-by-Step Examples with MySQL
Let’s create a sample employees
table to demonstrate the usage of the <
operator.
1. Creating the Table and Inserting Data
We will create an employees
table with columns id
, name
, age
, and salary
.
CREATE TABLE employees (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50),
age INT,
salary DECIMAL(10,2)
);
Inserting sample data into the table:
INSERT INTO employees (name, age, salary)
VALUES
('Arjun', 30, 50000.00),
('Ram', 25, 45000.00),
('John', 28, 48000.00),
('Priya', 23, 40000.00);
Examples: Using the Less Than Operator in Queries
Now, let’s explore different scenarios using the <
operator in SQL queries.
Example 1: Selecting Employees Younger Than 28
To retrieve employees who are younger than 28 years:
SELECT * FROM employees
WHERE age < 28;

Explanation:
- This query selects employees where the
age
is less than 28. - The output includes
Ram
(25 years) andPriya
(23 years).
Example 2: Selecting Employees with Salary Less Than 48000
To retrieve employees earning less than 48000:
SELECT * FROM employees
WHERE salary < 48000.00;

Explanation:
- This query selects employees where the
salary
is less than 48000. - The output includes
Ram
(45000) andPriya
(40000).
Conclusion
In this SQL Less Than operator tutorial, we covered:
- The syntax of Less-than operator.
- Example to use the
<
operator in real-world scenarios with age and salary comparisons.