This lesson is in the early stages of development (Alpha version)

Operators

Overview

Time: 20 min
Objectives
  • Understanding the concepts of Operators using SQL

OPERATORS

The operators help perform operations on the data in the table. They can be used to perform arithmetic operations or filter based on certain conditions.

Consider the below table:

Opt_1

ARITHMETIC OPERATORS:

The arithmetic operators help perform arithmetic operations on the data in the table

Opt_2

Example:

SELECT ProductID, Unit, Price, Price * Unit AS Total_sales, Price % Unit AS Modulo_result FROM Products

Opt_3

COMPARISON OPERATORS:

The comparison operators are used to filter the results based on a condition. They are generally passed in the WHERE clause and filters the result based on the condition provided.

Opt_4

Syntax:

SELECT columns FROMv table_name WHERE condition <comparison_operator_of_choice> value

Examples:

SELECT ProductID, ProductName, Price FROM Products WHERE ProductID <= 15

Opt_5

SELECT ProductID, ProductName, Price FROM Products WHERE Price = 18

Opt_6

LOGICAL OPERATORS:

SQL has three logical operators which can be used to specify more than one condition in the WHERE clause.

The three operators are:

Syntax:

SELECT columns FROM table_name WHERE condition1 AND/OR condition2
SELECT columns FROM table_namem WHERE NOTcondition

Examples:

SELECT CustomerName, Country, City, PostalCode
From Customers
Where Country = 'Brazil' AND City = 'São Paulo'

Opt_7

SELECT CustomerName, Country, City, PostalCode
From Customers
Where City = 'Nantes' OR City = 'Paris'

Opt_8

SELECT CustomerName, Country, City, PostalCode
From Customers
Where Not City = 'London'

Opt_9

Key Points

  • Familiarize with Arithmetic operations, Comparison operators and Logical Operators