In SQL, Operators are special character, symbol or a keyword that is used to perform some specific operations. For example : comparing data
SQL operators are commonly used with SQL statements to retrieve, filter, and manipulate data.
SQL comparison operators can be used to compare values and filer the data.
• Equal to = • Not equal to <> or != • Greater than > • Less than < • Greater than or equal to >= • Less than or equal to <=
Let's assume we have a table named "[Employees]".
It is a operator denoted by equal to (=) symbol and use to check if two values are matching.
Write a SQL statement to retrieve employees data from [Employees] table where Employee_Id is equal to 3.
SELECT * FROM [Employees] WHERE Employee_Id = 3;
By using 'Equal to' operator, above statement returned a single row because [Employees] table contains only one row where Employee_id is equal to 3.
It is a operator denoted by either the (<>) or (!=) symbols and use to check if two values are not matching.
Write a SQL statement to retrieve employees data from [Employees] table where Gender is not equal to 'Male'.
SELECT * FROM [Employees] WHERE Gender != 'Male';
By using 'Not equal to' operator, above statement returned a 2 rows because [Employees] table contains two rows where Gender is not equal to 'Male'.
It is a operator denoted by (>) symbol and use to check if a value is greater than other values.
Write a SQL statement to retrieve employees data from [Employees] table where salary is greater than 4000.
SELECT * FROM [Employees] WHERE Salary > 4000;
By using 'Greater than' operator, above statement returned a single row because [Employees] table contains only one row where Salary is greater than 4000.
It is a operator denoted by (<) symbol and use to check if a value is less than other values.
Write a SQL statement to retrieve employees data from [Employees] table where salary is less than 3000.
SELECT * FROM [Employees] WHERE Salary < 3000;
By using 'Less than' operator, above statement returned a 2 rows because [Employees] table contains two rows where Salary is less than 3000.
It is a operator denoted by (>=) symbol and use to check if a value is greater than or equal to other values.
Write a SQL statement to retrieve employees data from [Employees] table where salary is greater than or equal to 4000.
SELECT * FROM [Employees] WHERE Salary >= 4000;
By using 'Greater than or equal to' operator, above statement returned a 2 rows because [Employees] table contains two rows where Salary is greater than or equal to 4000.
It is a operator denoted by (>=) symbol and use to check if a value is less than or equal to other values.
Write a SQL statement to retrieve employees data from [Employees] table where salary is less than or equal to 2000.
SELECT * FROM [Employees] WHERE Salary <= 2000;
By using 'Less than or equal to' operator, above statement returned a 2 rows because [Employees] table contains two rows where Salary is less than or equal to 2000.
Comparison operators in SQL include "=", "<>", ">", "<", ">=", and "<=".
The six comparison operators are "=", "<>", ">", "<", ">=", and "<=".
In SQL Server, you use "=" instead of "==" for comparison.
Comparison operators in SQL include "=", "<>", ">", "<", ">=", and "<=".