How to Use Comparison Operators in SQL

Posted by tagicon_admin | September 10, 2015 | in : SQL

What is Comparison Operators in SQL?

Basically comparison operators are used to compare one expression with another value or expression. This operators are used in WHERE clause. Compare data must be same data type. When we need specific data or filter data from data based then we can use this operators.

Now I am showing a list of comparison operators that are used in SQL:

–>=Equal
–><>Not Equal
–>!=Not Equal
–>^=Not Equal
–>>Greater Than
–>>=Greater Than or Equal to
–><Less Than
–><=Less Than or Equal to
–>IN()Matches value from list
–>BETWEENFor range(inclusive)
–>IS NULLIs a null value
–>IS NOT NULLNon-NULL value

 

Syntax of Comparison Operators in SQL:

SELECT column_name, column_name
FROM table_name
WHERE column_name operator value;

Equal(=) Operator in SQL:

When we need specific data or test quality within two data, numbers or expressions then we use equal (=) operator.

Example:

 

Answer:

 

SQL Statement:

Answer:

SQL Statement:

Answer:

 

SQL Statement:

Answer:

 

Not Equal(<>, !=, ^=) Operator in SQL:

We can easily identify our specific data by using Not Equal Operator. When we need to data that are not equal with other data than we can use this operator.

Example:

Answer:

 

SQL Statement:

Answer:

 

SQL Statement:

Answer:

 

SQL Statement:

Answer:

 

Greater Than (>) Operator in SQL:

When we need big value or greater value from expressions or data then we use greater than operator.

Example:

Answer:

 

SQL Statement:

Answer:

 

Greater Than or Equal to (>=) Operator in SQL :

When we need value that are greater than or equal from other expressions or values then we can use greater than or equal to operator.

Example:

Answer:

 

Less Than (<) Operator in SQL :

Less than operator is opposite of greater than operator. When we need small value from other expression, we can use less than operator.

Example:

Answer:

 

SQL Statement:

 

Answer:

 

Less Than or Equal to (<=) Operator in SQL :

Less than or equal to operator is opposite of greater than or equal to operator. We need small value or same value from other expression then we can use this operator.

Example:

Answer:

 

SQL Statement:

 

Answer:

 

IN() operator in SQL :

IN operator is used to find a set of value from database.

Example:

 

Answer:

SQL Statement:

 

Answer:

 

BETWEEN Operator in SQL :

BETWEEN operators are used to select values within a range.

Example:

Answer:

SQL Statement:

 

Answer:

 

IS NULL operator in SQL :

When we need data from database that are null then we can use IS NULL operator. IS NULL operator is used to identify null value.

Example:

 

Answer:

 

IS NOT NULL operator in SQL:

IS NOT NULL operator is opposite of IS NULL operator. IS NOT NULL operator is used to identify value that are not null.

Example:

 

Answer:

 

Related Posts

Leave a Reply