SQLforGeeks
  • Home
  • SQL
  • SQL Tutorial
  • SQL Syntax
  • Services
  • Product
    🏋️ GyManage 📱 More to come
Contact
  1. SQL
  2. SQL Comparison operators

Text copied!

« Previous
Next »

SQL Comparison operators

May 19, 2023, 8:02 p.m. under SQL

  • Hi! You should check SQL arithmetic operators post first.

    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.

    Overview of SQL comparison operators :
    • 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]".

    SQL Comparison operators
    1. Equal to :

    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;
            
    SQL Comparison operators

    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.

    2. Not equal to :

    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';
            
    SQL Comparison operators

    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'.

    3. Greater than :

    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;
            
    SQL Comparison operators

    By using 'Greater than' operator, above statement returned a single row because [Employees] table contains only one row where Salary is greater than 4000.

    4. Less than :

    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;
            
    SQL Comparison operators

    By using 'Less than' operator, above statement returned a 2 rows because [Employees] table contains two rows where Salary is less than 3000.

    5. Greater than or equal to :

    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;
            
    SQL Comparison operators

    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.

    6. Less than or equal to :

    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;
            
    SQL Comparison operators

    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.

    To enhance your understanding of 'SQL operators', be sure to check out our next tutorial.

    Frequently Asked Questions :

    What are the comparison operators in SQL?

    Comparison operators in SQL include "=", "<>", ">", "<", ">=", and "<=".

    What are all 6 comparison operators?

    The six comparison operators are "=", "<>", ">", "<", ">=", and "<=".

    How to use == in SQL Server?

    In SQL Server, you use "=" instead of "==" for comparison.

    Which are comparison operators?

    Comparison operators in SQL include "=", "<>", ">", "<", ">=", and "<=".
    Thank You! You should check SQL logical operators post next.
    « Previous
    Next »
    RELATED :

    What is SQL

    What is T-SQL

    Difference between DBMS and Data Warehouse

    Download SQL Server

    Install SQL Server

    Download SQL Server Management Studio SSMS

    SQL Server Management Studio

    SQL Database

    Download database

    Restore database

    Backup database

    Attach database

    Detach database

    Create database

    Delete database

    Rename database

    Select database

    Database offline

    Database online

    SQL Commands

    SQL Tables

    Create table

    Truncate table

    Delete table

    Rename table

    Select table

    Alter table

    SQL Data Types

    SQL Comments

    SQL Constraints

    SQL Joins

    SQL inner join

    SQL left join

    SQL right join

    SQL full join

    SQL cross join

    SQL self join

    INSERT INTO SELECT statement

    INSERT INTO statement

    SQL Clauses

    SELECT clause

    FROM clause

    WHERE clause

    GROUP BY clause

    HAVING clause

    ORDER BY clause

    JOIN clause

    UNION clause

    UNION ALL clause

    TOP clause

    DISTINCT clause

    SQL Operators

    SQL Arithmetic operators

    SQL Logical operators

    UNION operator

    UNION ALL operator

    INTERSECT operator

    EXCEPT operator

    LIKE operator

    NOT LIKE operator

    IN operator

    NOT IN operator

    IS NULL operator

    IS NOT NULL operator

    EXISTS operator

    NOT EXISTS operator

    BETWEEN operator

    NOT BETWEEN operator

    SQL Functions

    SQL Built-In functions

    CHARINDEX function

    DATEADD function

    CONCAT function

    LEN function

    REPLACE function

    SUBSTRING function

    CASE statement

    GETDATE function

    DATEPART function

    DATEDIFF function

    CAST function

    TRY_CAST function

    CONVERT function

    TRY_CONVERT function

    ISNULL function

    NULLIF function

    COALESCE function

    SQL Window functions

    ROW_NUMBER function

    RANK function

    DENSE_RANK function

    IIF function

    CHOOSE function

    SQL Store Procedure

    Store Procedure vs. Function

    SQL Subquery

    SQL Aliases

    Temp table

    SQL Error Handling

    SQL Variables

    SQL Views

    SQL Merge

    SQL CTE

    SQL WITH TIES

    Define Transaction in DBMS

    ACID properties in DBMS

    Types of Triggers in DBMS


    • Have Some Questions?
    logo

    Elevate your data experience with SQL excellence

    Quick Links
    •  Home
    •  SQL Tutorial
    •  SQL Syntax
    •  Our Services
    Our Services
    • Web Development
    • BI Development
    • Data Warehousing
    • Data Integration ETL


    Follow Us

    GST Registered: XXAXXXXXXXZX
    Mumbai, Maharashtra, India

    © 2024 Copyright | All Rights Reserved | Legal