# 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.

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

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

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 StCNTDS As String
Dim DBPath As String
Dim StRsVendor As String

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

excel remove duplicates in a columncomplex pivot tablesaccess vba run macroexcel vba select columnworkbook close vbams access vba delete recordrange vba variablehow to develop macros in excelduplicate numbers in excelvba adodb referencedeleting blank rows in excelms excel formulas with examples for 2007run macro vbaistext excelexcel formula columnvlookup explained in simple termstutorial excel macrosexcel function in vbamicrosoft vba excelexcel formula to find duplicates in a listexcel vba range copyvba fillvariant data type in vbunlock protected sheet excelunlocking excel spreadsheetvba stands forestimate spreadsheet templatepivot table charts excel 2010vba numberformatinterior.color vbavba data entry formunprotect excel macrovba hello worlddelete empty rows in excel 2007sql sorted byremove duplicate rows from excelvlookups tutorialauto column width excelvba excel codeactivex listboxdaily log template excelwhat are dashboards in excelvba rows selectssis check if file existsexcel 2007 all formulas with examplessample project timeline excelmeaning of excel in hindisave excel vbaunload me vba excelsql compare operatorspivot table field name already existssas macro interview questionsfind duplicate entries in excelmeeting minute template exceluser forms vbahow to insert macro button in excel 2010excel macro print to pdfsql technical interview questions and answers pdflookup excel formulaexcel formula to calculate difference between two datesvba create comboboxexcel vba inputvba progress bar examplesql query for beginnerslen excelrecord macro excel 2007working with pivot tables in excel 2007sumif excel examplesexcel hyperlink to cellhow to protect a worksheet in excel 2007update screen vbavba isnumvb message box yes noisevenms access export to excel vbavba example programsplsql for dummiesautofit cells in excelshortcut key to change the sheet in excelmerge multiple rows in excel