SQL Server Comparison Operator

Last updated on Dec 19 2021
Amit Warghade

Table of Contents

SQL Server Comparison Operator

In SQL Server, the comparison operators are wont to test for equality and inequality. These operators are utilized in the WHERE clause to work out which records to pick.

Following may be a list of the SQL Server comparison operators:

Index Comparison Operator Description
1) = It specifies equal symbol.
2) <> It specifies not equal symbol.
3) != It specifies not equal symbol.
4) > It specifies greater than symbol.
5) >= It specifies greater than or equal symbol.
6) < It specifies less than symbol.
7) <= It specifies less than or equal symbol.
8) !> It specifies not greater than symbol.
9) !< It specifies not less than symbol.
10) IN ( ) It matches a value in a list.
11) NOT It is used to negate a condition.
12) BETWEEN It is used to specify within a range (inclusive) value.
13) IS NULL It specifies null value.
14) IS NOT NULL It specifies non-null value.
15) LIKE It specifies pattern matching with % and _
16) EXISTS It specifies that the condition is met if subquery returns at least one row.

 

Equality Operator

In SQL Server database, Equality Operator “=” is employed to check for equality during a query.

Example:

We have a table named “Employees”, having the subsequent data:

Page 2 Image 1 6
equality

Use the subsequent query to pick the precise data where “name” = “Lily”:

  1. SELECT *
    FROM [tecklearn].[dbo].[Employees]
    WHERE name = 'Lily';

Output:

Page 3 Image 2 8
Lily

Inequality Operator

In SQL Server, inequality operators ” or !=” are wont to test for inequality during a query.

  1. SELECT *
    FROM [tecklearn].[dbo].[Employees]
    WHERE name 'Lily';

Output:

Page 4 Image 3 6
or

OR

  1. SELECT *
    FROM [tecklearn].[dbo].[Employees]
    WHERE name != 'Lily';

Output:

Page 5 Image 4 5
name!

Greater Than Operator

Greater Than “>” Operator is employed to check for an expression that it’s “greater than”.

Example:

Let’s select employees from the table “Employees” where salary > 15000.

  1. SELECT *
    FROM [tecklearn].[dbo].[Employees]
    WHERE salary > 15000;

Output:

Page 6 Image 5 5
greater than

Greater Than or Equal Operator

Greater Than or Equal “>=” Operator is employed to check for an expression that it’s “greater than or equal to”.

  1. SELECT *
    FROM [tecklearn].[dbo].[Employees]
    WHERE salary >= 15000;

Output:

Page 7 Image 6 1
greater than equal to

Less than Operator

Less Than “<” Operator is employed to check for an expression that it’s “less than” the opposite one.

Example:

Select all employees from the table “Employees” where salary is < 20000.

  1. SELECT *
    FROM [tecklearn].[dbo].[Employees]
    WHERE salary < 20000;

Output:

Page 8 Image 7 1
less than

Less Than or Equal Operator

Less Than or Equal “<=” “<=” Operator is used to test for an expression that it is “less than or equal to” the other one.

  1. SELECT *
    FROM [tecklearn].[dbo].[Employees]
    WHERE salary <= 20000;

Output:

Page 9 Image 8 1
less than equal to

So, this brings us to the end of blog. This Tecklearn ‘SQL Server Comparison Operator’ blog helps you with commonly asked questions if you are looking out for a job in MS-SQL Server. If you wish to learn MS-SQL Server and build a career in Database domain, then check out our interactive, MS-SQL Server Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/ms-sql-server-training-and-certification-course/

MS-SQL Server Training

About the Course

Microsoft SQL Server training course is an online classroom training meant for developers to master the descriptive language to work for relational databases. Important topics included in this SQL course are SQL introduction, relational databases, queries, subqueries, joins, and unions. After completing this course, you will also become proficient in the theory of optimization, transactions, indexing, installing SQL Server, database administration, clustering, implementing programmability objects, designing and implementing database objects, managing database concurrency, and optimizing SQL infrastructure and database objects.

Why Should you take MS-SQL Server Training?

  • The average salary for Sql server developer ranges from approximately $88,666 per year for Database Developer to $115,811 per year for Senior SQL Developer. – Indeed.com
  • Wells Fargo, UPS, US Bank, Perspecta, Silicon Valley Bank, Mindtree Wipro, Infosys & many other MNC’s worldwide use MS SQL Server for their Database deployments.
  • According to Gartner, MS SQL Server is the market leader in the Relational Database with 18.5% market share globally.

What you will Learn in this Course?

Introduction to SQL

  • Various types of databases
  • Introduction to SQL
  • Installation Steps of MS-SQL Server
  • Overview of Microsoft SQL Server Management Studio
  • SQL architecture, client/server relation
  • Database types

Introduction to relational databases, basic concepts of relational tables

  • Working with rows and columns
  • Various operators used like logical and relational
  • Constraints, Primary Key and Foreign Key
  • Insert, Update, Delete, Alter

Working with SQL: Join, Tables, and Variables

  • SQL Operators and Queries
  • SQL functions
  • Creation of Table
  • Retrieval of Data from tables
  • Combining rows from tables using joins
  • Operators such as intersect, except, union, temporary table creation, set operator rules, table variables etc

Deep Dive into SQL Functions

  • Data Retrieval Language
  • Functions
  • Operators
  • Clauses
  • Sub-Queries
  • Correlated Sub-Queries

SQL Views, Functions

  • Sub-queries
  • Views
  • Indexes

Managing Data with Transact-SQL

  • Transact-SQL queries
  • Implementing functions and aggregating data
  • Determining the results of DDL statements on supplied tables and data

Cursor Management and Triggers

  • Cursors
  • Triggers
  • Types of Triggers

Stored Procedures and User Defined functions

  • Understanding of Stored Procedures
  • Key benefits of Stored Procedures
  • Studying user-defined functions

Deep Dive into User-defined Functions

  • Detailed study of user-defined functions
  • Various types of UDFs like Scalar, Inline Table Value, multi-statement Table
  • What is Rank Function? Triggers, when to execute Triggers?

SQL Optimization and Performance

  • Concepts of Concurrency and Locking behaviour
  • Usage of memory-optimized tables to solve issues
  • Examining and Troubleshooting of query plans
  • Performance management of Database instances
  • SQL server Performance Monitoring

Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "SQL Server Comparison Operator"

Leave a Message

Your email address will not be published. Required fields are marked *