Summary: In this tutorial, We’re going to cover what exactly SQL query operators (SQL Operators) are, before providing a comprehensive list of the different types with full examples for each.
Introduction Of SQL Query Operators
An SQL Query Operators are used mainly in an SQL Server statement’s WHERE clause to perform an operation(s), like comparisons, Arithmetic, & logical operations. this operator is a reserved character, which is used for the purpose of specifying the conditions during an SQL statement and to serve as conjunctions for multiple conditions in a statement.
Arithmetic operators
Comparison operators
Logical operators
Operators used to negate conditions
A) SQL Arithmetic Operators
Assume that ‘variable a’ holds 100 and ‘variable b’ holds 200, then −
Operator
Description
Example
Addition (+)
The addition operator will add values on either side of the operator.
a + b will give 300
Subtraction (-)
The subtraction operator will subtract the right-hand operand from the left-hand operand.
a – b will give -100
Multiplication (*)
The multiplication operator will multiply values on either side of the operator.
a * b will give 20000
Division (/)
The division operator will divide the left-hand operand by the right-hand operand.
b / a will give 2
Modulus (%)
The modulus operator will divide the left-hand operand by the right-hand operand and returns the remainder.
Assume that ‘variable a’ holds 100 and ‘variable b’ holds 200, then −
Operator
Description
Example
=
This operator is used to check the values of both operands are equal or not, if they are equal then returns true.
(a = b) is not true
!=
This operator is used to check the values of two operands are equal or not, if they aren’t equal then returns true.
(a != b) is true
>
To check the value of the left operand is greater than the value of the right operand, if this condition becomes true then it returns true.
(a > b) is not true.
<
This operator is used to check whether the value of the left operand is less than the value of the right operand, if the condition is true then return true.
(a < b) is true.
<>
To check the values of two operands are equal or not, If they are not equal then, it returns TRUE.
(a <> b) is true
>=
This operator will be used for the purpose of to checks if the value of the left operand is greater than or equal to the value of the right operand, if the condition becomes true then returns true.
(a >= b) is not true.
<=
This is used for the purpose of to checks if the value of the left operand is less than or equal to the value of the right operand, if the condition becomes true then returns true.
(a <= b) is true.
!<
This operator will be used to check if the value of the left operand isn’t less than the value of the right operand, if the condition is true then return true.
(a !< b) is false.
!>
It will be used to check if the value of the left operand isn’t greater than the value of the right operand, if the condition is true then return true
(a !> b) is true.
Demo Table: Students
Let’s see to better understanding the example, Here, i will consider the following given below table to perform various operations.
StudentID
FirstName
LastName
City
Age
1
Saumya
Tripathi
Noida
32
2
Pushpendra
Verma
Gr. Noida
31
3
Mohit
Chauhan
Jhasi
28
4
Akanksha
Jain
Lucknow
29
5
Satendra
Singh
Kanpur
30
Example:
Example[Use equal to]:
SELECT * FROM Students
WHERE Age = 28;
StudentID
FirstName
LastName
City
Age
3
Mohit
Chauhan
Jhasi
28
Example[Use greater than]:
SELECT * FROM Students
WHERE Age > 30;
StudentID
FirstName
LastName
City
Age
1
Saumya
Tripathi
Noida
32
2
Pushpendra
Verma
Gr. Noida
31
Example[Use Less than]:
SELECT * FROM Students
WHERE Age < 29;
StudentID
FirstName
LastName
City
Age
3
Mohit
Chauhan
Jhasi
28
Example[Use less than or equal to]:
SELECT * FROM Students
WHERE Age <= 29;
StudentID
FirstName
LastName
City
Age
3
Mohit
Chauhan
Jhasi
28
4
Akanksha
Jain
Lucknow
29
Example[Not equal to]:
SELECT * FROM Students
WHERE Age != 30;
StudentID
FirstName
LastName
City
Age
1
Saumya
Tripathi
Noida
32
2
Pushpendra
Verma
Gr. Noida
31
3
Mohit
Chauhan
Jhasi
28
4
Akanksha
Jain
Lucknow
29
C) SQL Logical Operators
Here is a list of all the logical operators which are available in SQL Server.
Operator
Description
ALL
The ALL operator is used for the purpose of comparing a value to all values in another value set.
AND
it permits the existence of multiple conditions in an SQL statement’s WHERE clause.
ANY
To compare a value to any applicable value within the list as per the condition.
BETWEEN
It is used to search for values that are within a set of values, given the minimum value & the maximum value.
EXISTS
To search for the existence of a row in a specified table that meets a certain criterion.
IN
It is used for the purpose of comparing a value to a list of literal values that have been specified.
LIKE
The LIKE operator is used for the purpose of comparing a value to similar values using wildcard operators.
NOT
The NOT operator in SQL Server reverses the meaning of the logical operator with which it is used. i.e NOT EXISTS, NOT BETWEEN, & NOT IN, etc. This is a negate operator.
OR
The OR operator is used for the purpose of combining multiple conditions in an SQL statement’s WHERE clause.
IS NULL
The NULL operator is used for the purpose of comparing a value with a NULL value.
UNIQUE
The UNIQUE operator in SQL is used for the searches of every row of a specified table for uniqueness (i.e. no duplicates).
Example:
To see the demonstration, I will consider the Students’ table considered above, to perform the Logical Operators operations.
Example[ANY]
SELECT * FROM Students
WHERE Age > ANY (SELECT Age FROM Students WHERE Age > 29);
StudentID
FirstName
LastName
City
Age
1
Saumya
Tripathi
Noida
32
2
Pushpendra
Verma
Gr. Noida
31
Example[BETWEEN & AND]
SELECT * FROM Students
WHERE Age BETWEEN 28 AND 30;
StudentID
FirstName
LastName
City
Age
3
Mohit
Chauhan
Jhasi
28
4
Akanksha
Jain
Lucknow
29
5
Satendra
Singh
Kanpur
30
Example[IN]
SELECT * FROM Students
WHERE Age IN('28', '30');
StudentID
FirstName
LastName
City
Age
3
Mohit
Chauhan
Jhasi
28
5
Satendra
Singh
Kanpur
30
SQL Query Operators: Conclusion
In this article, You have learned SQL Query Operators (SQL Operators). Here, I have explained only a few demonstrations. I would say, that go ahead & practice for more examples on the different types of operators to get good practice on writing SQL queries.
Used to monitor number of Google Analytics server requests when using Google Tag Manager
1 minute
_gid
ID used to identify users for 24 hours after last activity
24 hours
_ga_
ID used to identify users
2 years
_gali
Used by Google Analytics to determine which links on a page are being clicked
30 seconds
_gac_
Contains information related to marketing campaigns of the user. These are shared with Google AdWords / Google Ads when the Google Ads and Google Analytics accounts are linked together.
90 days
__utmx
Used to determine whether a user is included in an A / B or Multivariate test.
18 months
__utmv
Contains custom information set by the web developer via the _setCustomVar method in Google Analytics. This cookie is updated every time new data is sent to the Google Analytics server.
2 years after last activity
__utmz
Contains information about the traffic source or campaign that directed user to the website. The cookie is set when the GA.js javascript is loaded and updated when data is sent to the Google Anaytics server
6 months after last activity
__utmc
Used only with old Urchin versions of Google Analytics and not with GA.js. Was used to distinguish between new sessions and visits at the end of a session.
End of session (browser)
__utmb
Used to distinguish new sessions and visits. This cookie is set when the GA.js javascript library is loaded and there is no existing __utmb cookie. The cookie is updated every time data is sent to the Google Analytics server.
30 minutes after last activity
__utmt
Used to monitor number of Google Analytics server requests
10 minutes
__utma
ID used to identify users and sessions
2 years after last activity
Jetpack's built-in visitor analytics. It records page views, referring sites, search terms, and outbound link clicks, and also carries the shared visitor-tracking library used by Jetpack Instant Search and WooCommerce Analytics.