# SQL Operators

Home/SQL/SQL Operators

SQL Operators helps us to write expressions in SQL queries. We use Arithmetic Operators, Comparison Operators, Logical Operators and Wildcard Operators while extracting and summarizing the data for analysis.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates

## SQL Arithmetic Operators

Following are the list of all the arithmetic operators available in SQL, assume variable a holds 100 and variable b holds 200 then:

Operator Description Example
+ Addition – Adds values on either side of the operator a + b will give 300
Subtraction – Subtracts right hand operand from left hand operand a – b will give -100
* Multiplication – Multiplies values on either side of the operator a * b will give 2000
/ Division – Divides left hand operand by right hand operand b / a will give 20
% Modulus – Divides left hand operand by right hand operand and returns remainder b % a will give 0

## SQL Comparison Operators

Following are the list of all the comparison operators available in SQL, assume variable a holds 100 and variable b holds 200 then:

Operator Description Example
= Checks if the value of two operands are equal or not, if yes then condition becomes true. (a = b) is not true.
!= Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a != b) is true.
<>  Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true.
Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (a > b) is not true.
Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (a < b) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a <= b) is true.
!< Checks if the value of left operand is not less than the value of right operand, if yes then condition becomes true. (a !< b) is false.
!> Checks if the value of left operand is not greater than the value of right operand, if yes then condition becomes true. (a !> b) is true.

## SQL Logical Operators

Following are the list of all the logical operators available in SQL:

Operator Description
ALL The ALL operator is used to compare a value to all values in another value set.
AND The AND operator allows the existence of multiple conditions in an SQL statement’s WHERE clause.
ANY The ANY operator is used to compare a value to any applicable value in the list according to the condition.
BETWEEN The BETWEEN operator is used to search for values that are within a set of values, given the minimum value and the maximum value.
EXISTS The EXISTS operator is used to search for the presence of a row in a specified table that meets certain criteria.
IN The IN operator is used to compare a value to a list of literal values that have been specified.
LIKE The LIKE operator is used to compare a value to similar values using wildcard operators.
NOT The NOT operator reverses the meaning of the logical operator with which it is used. Eg. NOT EXISTS, NOT BETWEEN, NOT IN etc. This is negate operator.
OR The OR operator is used to combine multiple conditions in an SQL statement’s WHERE clause.
IS NULL The NULL operator is used to compare a value with a NULL value.
UNIQUE The UNIQUE operator searches every row of a specified table for uniqueness (no duplicates).

## SQL Wildcard Operators

Following are the list of all the wildcard operators available in SQL, we use wildcard operators in conjunction with the LIKE operator:

Operator Description
The percent sign (%) Matches one or more characters. Note: MS Access uses the asterisk (*) wildcard character instead of the percent sign (%) wildcard character.
The underscore (_) Matches one character. Note: MS Access uses a question mark (?) instead of the underscore (_) to match any one character.
Character list to match (
[character list])
Sets and ranges of characters to match.
Character list not to match (^[character list]) Sets and ranges of characters to match.

#### Examples:

SQL Statement Description

Select * From Employee Where Name Like ‘M%’

Returns all the records where name starts with M

Select * From Employee Where Salary Like ‘2___0’

Returns all the records where it finds salary with a five-digit number that start with 2 and end with 0

Select * From Employee Where Department Like ‘[A-H]%’

Returns all the records where Department name start with any letter between A and H
Select * From Employee Where Department Like ‘^[A-H]%’

Returns all the records where Department name not start with any letter between A and H
LIMITED TIME OFFER
By |January 13th, 2013|SQL|1 Comment

### About the Author: PNRao

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

### One Comment

1. MANOHARAN January 8, 2016 at 4:34 PM - Reply

SIR THE B/M QUERY IS NOT WORKING PLEASE ASSIST ME

Sub CheckVendor()

Dim CnTDS As New ADODB.Connection
Dim StCNTDS As String
Dim DBPath As String
Dim StRsVendor As String
Dim RsVendor As New ADODB.Recordset

DBPath = ThisWorkbook.FullName
StCNTDS = “Provider=MSDASQL.1;DSN=Excel Files;DBQ=” & DBPath & “;HDR=Yes’;”
CnTDS.Open StCNTDS

StRsVendor = “Select [CREDITORS\$].[Account Code],[CREDITORS\$].[Name]” & _
“From [CREDITORS\$],[MASTER\$]” & _
“Where [CREDITORS\$].[Account Code] [MASTER\$].[Account Code]” & _
“Group By [CREDITORS\$].[Account Code],[CREDITORS\$].[Name];”

RsVendor.Open StRsVendor, CnTDS

Sheets(“NotFound”).Range(“A2”).CopyFromRecordset RsVendor

‘RsVendor.RecordCount = Nothing

End Sub

## Related pages

microsoft project timeline templatexldown vbavba activate sheetexcel keystrokesexcel vba switch casevba savevba leftvlook up functionhide worksheets in excelxlsm to xmlwhat is ddl and dml in sqlvlookup functionexcel infographic dashboardhow to arrange numbers in excelsumif formulas in excelsql server query exampletotal rows and columns in excel 2010excel vba loopexcel vba print userformvba select case multiple conditionshow to delete columns in excelif statement excel 2010microsoft excel autofitsumif formula exampleexcel 2007 concatenateexcel formula cell colorunderstanding vbahow to build dashboards in excelunlock excel fileexcel concatinationexcel consolidate functionaccess vba sqlvba clean functioncombine multiple sheets into one sheet excelwhat is dcl in sqlexcel countifs functionexcel 2007 stacked bar chartvba excel delete columnenable developer tab excelvba if iserrorhow to unlock an excel spreadsheet without the passwordproject portfolio dashboard templateddl dml dcl tcl commandstimeline templates for excelrefresh excel sheetremoving empty rows in excelexcel formulas to find duplicateswrite sql query in excelhow to consolidate excel sheetsvisual basic editor excel 2007excel shortcut delete rowexamples of excel spreadsheetshow to record a macro in excel 2007change width of column in excel 2010xml vbavba datevaluehow to highlight duplicates in excelremove hyperlinks excelvba create tablevba range autofilteroffset excel examplegoto statement vbashortcut keys of excel 2007excel exercise for job interviewhow to setup a macro in excelvba access tutorial pdfmacro to delete duplicate rowsvba msgbox yesnohow to put alphabetical order in excelmerge multiple columns in excelhow to unlock protected cells in excelexcel project tracker dashboardmacro to delete rows in excelto unprotect excel sheetword 2013 developer tab