Instagram
youtube
Facebook
Twitter

MS SQL Server Comparison Operator

MS SQL Server Comparison Operator

  • Comparison Operators are used with the WHERE clause to test for equality and inequality.
  • List of Operators:
Index Comparison Operator Description
1  = Equal Symbol
2  <> or !=  Not Equal Symbol
3  >  Greater than Symbol
4  >=  Greater than or equal Symbol
5  <  less than symbol
6  <=  less than or equal symbol
7  !> not greater than a symbol
8  !< not less than symbol
9  IN()  Matches value in a list
10 NOT  Negate a condition
11 BETWEEN  Range Value
12  IS NULL  NULL value
13 IS NOT NULL  Non NULL value
14 LIKE  Pattern Matching
15 EXISTS  Condition is met id subquery return at least one records

 

Example1:

SELECT * FROM [University].[dbo].[Student] WHERE Name='Ravi';

Output:

Id Name Branch CGPA
EN19CS301254 Ravi CSE 9.86

 

Example 2:

SELECT * FROM [University].[dbo].[Student] WHERE Name<>'Ravi';

or

SELECT * FROM [University].[dbo].[Student] WHERE Name!='Ravi';

Output:

Id Name Branch CGPA Age
EN19CS301246 Savi CSE 9.23 18
EN19CS301248 Aayush CSE 7.25 20
EN19CS301258 Kavi CSE 7.50 19

 

Example 3:

SELECT * FROM [University].[dbo].[Student] WHERE CGPA>7.5;

Output:

Id Name Branch CGPA Age
EN19CS301254 Ravi CSE 9.86 19 
EN19CS301246 Savi CSE 9.23 18

 

Example 4:

SELECT * FROM [University].[dbo].[Student] WHERE CGPA>=7.5;

Output:

Id Name Branch CGPA Age
EN19CS301254 Ravi CSE 9.86 19 
EN19CS301246 Savi CSE 9.23 18
EN19CS301258 Kavi CSE 7.50 19

 

Example 5:

SELECT * FROM [University].[dbo].[Student] WHERE Age<20;

Output:

Id Name Branch CGPA Age
EN19CS301254 Ravi CSE 9.86 19 
EN19CS301246 Savi CSE 9.23 18
EN19CS301258 Kavi CSE 7.50 19

 

Example 6:

SELECT * FROM [University].[dbo].[Student] WHERE Age<=20;

Output:

Id Name Branch CGPA Age
EN19CS301254 Ravi CSE 9.86 19 
EN19CS301246 Savi CSE 9.23 18
EN19CS301248 Aayush CSE 7.25 20
EN19CS301258 Kavi CSE 7.50 19