sql operators

sql operators SQL Operators in DBMS , operator in sql

SQL operators is One of the important components of SQL that allow developers to perform numerous operations on records saved within a database.
Structured Query Language (SQL) is used to manipulate relational databases.

In this article, we will see operators in SQL detail.
Operators are used to Filter the sql data, If we have to add two fields, we can use arithmetic operators in sql. Or we can perform any mathematical operation on data using an arithmetic operator. Let’s see SQL operators in detail with an example.

Types of SQL Operators:

SQL Operators in DBMS

SQL operators devided into different categorized based on their functions:

Arithmetic Operators:

Arithmetic Operators: These operators perform mathematics calculations on numeric information types. The general mathematics operators encompass (addition), – (subtraction), * (multiplication), / (division), and % (modulo).
Arithmetic Operator in SQL is used to add , subtract ,divide or multiply different column values.

Example of Arithmetic Operators

select EmployeeBasicSal+EmployeeDASal as totalSal from Employee
arithmatic operator
arithmetic operator in sql

Calculations: Arithmetic operators allow appearing calculations on information, like computing the overall salary through including EmployeeBasicSal and EmployeeDASal (basic salary and DA salary is added using arithmetic operator)

Comparison Operators: Comparison operators are used to examine values within a query.

They encompass = (same to), != or <> (now not equal to), < (much less than), > (extra than), <= (much less than or identical to), and >= (more than or same to).
Comparison Operators in sql are used to fetch the conditional data with applying less , equal, and greater etc. you can fetch the data with specific filter to column

Comparison Operators:

Example

select *  from Employee where EmployeeSalary > 40000

select * from Employee where EmployeeDOJ>='01-oct-2015'
comparison operator 2
Comparison operator in sql

Logical Operators:

Logical Operators: Logical operators allow you to combine the conditions and create complex standards. Common logical operators includes AND, OR, and NOT.
Logical Operators are used to combine or to apply conditions to tables fields

select * from Employee where EmployeeDOJ>='01-oct-2015' AND EmployeeGrade='A'

select * from Employee where EmployeeDOJ>='01-oct-2015' OR EmployeeGrade<> 'A'
logical operator 1
Logical Operators in sql

Combining Conditions: Logical operators let you combine more than one situation to create complicated filters, inclusive of retrieving employees whose EmployeeDOJ greater than ’01-oct-2015′ and EmployeeGrade is ‘A’.
in this operator AND is used to apply both the conditions to sql query AND operator will validate EmployeeDOJ AND EmployeeGrade

Nullity Operators:

Nullity Operators: These operators are used to test for NULL values. The IS NULL and IS NOT NULL operators help filter out records that have NULL or non-NULL values in database tables columns.

Example


select * from Employee where EmployeeEmail is NULL

select * from Employee where EmployeeEmail is NOT NULL
Nullity operator 1
Null operators in sql

Handling Null Values: Nullity operators help in figuring out statistics with missing or non-lacking statistics.
this will help to find NULL values in the table or you can filter NOT NULL values in the database tables
We can Find NULL or NON null Values using IS NULL and IS NOT NULL sql Operator

Pattern Matching Operators:

Pattern Matching Operators: These operators are used to in shape patterns within strings. The two number one sample matching operators are LIKE and ILIKE (case-insensitive LIKE), that are often used with wildcard characters % (suits any series of characters) and _ (suits any unmarried man or woman).

select * from Employee where EmployeeName like 'RA%'

Like Operator is used to find the string Starting from RA in the EmployeeName field

pattern matching operator
pattern matching operators : like

IN Operator:

IN Operator: The IN operator is used to fit a EmployeeID against a listing of values.
now will show the result of Employee where EmployeeID 98,457

select * from Employee where EmployeeID in (98,457)
in operator 1
in operator

In this operator you can write select query records in i.e. select EmpID from employee where EmpId in (select EmpID from newEmployee where DOB >07-dec-1995)

BETWEEN Operator

this BETWEEN Operator: The BETWEEN operator extract the values within given range.

select * from employee where employeeDOJ between '01-jan-2010' and '31-dec-2015'

select * from employee where employeeID between 1 and 4
between operator
between operator

the between operator is used to find the values in given range for example here you will see the list of Employee where EmployeeID between 1 and 4. from 1 to 4 ID’s Employee will be displayed in result.

Operators in SQL Queries:

SQL operators are necessary to develop powerful and unique queries. They permit developers to filter and manage information in keeping with particular requirements.

Filtering Data:

Comparison operators are used to retrieve records based totally on positive conditions, which includes retrieving products with a EmployeeSal extra than a particular Amount (40000)or Date of joining greater than specific date.

Combining Conditions:

Logical operators let you combine more than one situations to create complicated filters, inclusive of retrieving employees who’s EmployeeDOJ greater than ’01-oct-2015′ and EmployeeGrade is ‘A’.
in this operator AND is used to apply both the conditions to sql query AND operator will validate EmployeeDOJ AND EmployeeGrade

Calculations:

Calculations: Arithmetic operators allow appearing calculations on information, like computing the overall salary through including EmployeeBasicSal and EmployeeDASal (basic salary and DA salary is added using arithmetic operator)

Pattern Matching:

Pattern Matching: Pattern matching operators like LIKE assist retrieve statistics based totally on precise patterns in string columns, like finding all EmployeeName whose Starting names start with “RA”.
Like Operator is used to find the string Starting from “RA” in the EmployeeName field

Handling Null Values:

Handling Null Values: Nullity operators help in figuring out statistics with missing or non-lacking statistics.
We can Find NULL or NON null Values using IS NULL and IS NOT NULL sql Operator

Click here how to restore db

Leave a Comment