Comparison Operators =, >, <, >=, <=, <>

Comparison Operators (=, >, <, >=, <=, <>)

In SQL database management systems, comparison operators are used to compare data values ​​in database table queries. Comparison operators help database users filter table data and extract table data and information based on specific conditions or logic.

Comparison Operators =, , , =, =,

So, let’s learn more about comparison operators in the SQL language.

Equals (=) Comparison Operator.

In SQL database tables, the = equals operator checks whether two compared values ​​are equal or not in the current table. The equals comparison operator generally helps compare two values.

Syntax of equals Comparison Operator.

SELECT column_name FROM table_name WHERE column_name = value;

Example of equals Comparison Operator.

SELECT * FROM employe WHERE department = ‘Marketing’;

This query extracts all row record information from the employe table where the employee’s department column has a column value equal to ‘Marketing’.

Greater Than (>) Comparison Operator.

The > Greater Than operator in a SQL database table checks whether a given numeric value is greater than or equal to the given numeric value. It finds the greater numeric value in the table based on the condition specified in the Greater Than operator and displays the query record or result.

Syntax of the Greater Than (>) comparison operator.

SELECT column_name FROM table_name WHERE column_name > value;

Example of the Greater Than (>) comparison operator.

SELECT * FROM employe WHERE salary > 50000;

This query extracts all row values ​​in the employe table where the employee’s salary is greater than ₹50,000.

Less Than (<) comparison operator.

In SQL database tables, the < less than operator checks whether the leftmost value in the current table is less than the rightmost value. Generally, the less than operator finds and displays or previews the less than column value among two values ​​based on a given condition in the table.

Less Than (<) comparison operator syntax.

SELECT column_name FROM table_name WHERE column_name < value;

Example of the less than (<) comparison operator.

SELECT * FROM employe WHERE emp_age < 40;

This query extracts all rows from the current employee table where the employee’s age is less than 40.

Greater Than or Equal To (>=) comparison operator.

Greater Than and Equal To in SQL database tables The >= operator checks whether the value on the left side is greater than or equal to the value on the right side in the current table. The Greater Than and Equal To operators find and display the greater than and equal to values ​​in a given table condition.

Greater Than or Equal To (>=) comparison operator syntax.

SELECT column_name FROM table_name WHERE column_name >= value;

Example of the Greater Than or Equal To (>=) comparison operator.

SELECT * FROM employe WHERE salary >= 30000;

This query displays all rows from the current Employee table where the employee’s salary is greater than or equal to 30000.

Less than or equal to (<=) comparison operator.

In SQL database tables, the <= less than and equal to operator checks whether the value on the left is less than or equal to the value on the right. It typically finds and displays less than or equal to values ​​in the current table based on a given condition.

Syntax of the Less Than or Equal To (<=) comparison operator.

SELECT column_name FROM table_name WHERE column_name <= value;

Example of the less than or equal to (<=) comparison operator.

SELECT * FROM employe WHERE emp_age <= 33;

This query displays all rows from the Employee table where the employee’s age is less than or equal to 33.

Not Equal (<> or !=) comparison operator.

In SQL database tables, the <> or != operator checks whether the value on the left in the current table is equal to, or not equal to, the value on the right. Typically, this operator finds not-equal values ​​in the current table and displays the row value.

Syntax of the Not Equal (<> or !=) comparison operator.

SELECT column_name FROM table_name WHERE column_name <> value;

– or

SELECT column_name FROM table_name WHERE column_name != value;

Example of the Not Equal (<> or !=) comparison operator.

SELECT * FROM employe WHERE department <> ‘Development’;

This query displays all table row records from the current employe table where department is not equal to ‘Development’.

Or, database users can apply the != operator instead.

SELECT * FROM employee WHERE department != ‘Design’;

Explanation about Comparison Operators.

SymbolOperator DescriptionExample of Comparison Operators  
=Equal to comparison operatorSELECT * FROM employe WHERE emp_age = 21;
Greater than comparison operatorSELECT * FROM employe WHERE salary > 30000;
Less than comparison operatorSELECT * FROM employe WHERE emp_age < 27;
>=Greater than or equal to comparison operatorSELECT * FROM employe WHERE salary >= 30000;
<=Less than or equal to comparison operatorSELECT * FROM employe WHERE emp_age <= 33;
<> / !=Not equal to comparison operatorSELECT * FROM employe WHERE department <> ‘ Design ‘;

Leave a Reply