- Python Basics
- Interview Questions
- Python Quiz
- Popular Packages
- Python Projects
- Practice Python
- AI With Python
- Learn Python3
- Python Automation
- Python Web Dev
- DSA with Python
- Python OOPs
- Dictionaries
SQL Operators
SQL Operators perform arithmetic, comparison, and logical operations to manipulate and retrieve data from databases.
In this article, we will discuss Operators in SQL with examples, and understand how they work in SQL.
Operators in SQL
Operators in SQL are symbols that help us to perform specific mathematical and logical computations on operands. An operator can either be unary or binary.
The unary operator operates on one operand, and the binary operator operates on two operands.
Types of Operators in SQL
Different types of operators in SQL are:
- Arithmetic operator
- Comparison operator
- Logical operator
- Bitwise Operators
- Compound Operators
SQL Arithmetic Operators
Arithmetic operators in SQL are used to perform mathematical operations on numeric values in queries. Some common arithmetic operators are:
SQL Arithmetic Operators Example
In this example, we will retrieve all records from the “employee” table where the “emp_city” column does not start with the letter ‘A’.
SQL Comparison O perators
Comparison Operators in SQL are used to compare one expression’s value to other expressions. SQL supports different types of comparison operator, which are described below:
SQL Comparison Operators Example
In this example, we will retrieve all records from the “MATHS” table where the value in the “MARKS” column is equal to 50.
SQL Logical Operators
Logical Operators in SQL are used to combine or manipulate conditions in SQL queries to retrieve or manipulate data based on specified criteria..
SQL Logical Operators Example
In this example, retrieve all records from the “employee” table where the “emp_city” column is equal to ‘Allahabad’ and the “emp_country” column is equal to ‘India’.
SQL Bitwise Operators
Bitwise operators in SQL are used to perform bitwise operations on binary values in SQL queries, manipulating individual bits to perform logical operations at the bit level. Some SQL Bitwise Operators are:
SQL Compound Operators
Compound operator in SQL are used to perform an operation and assign the result to the original value in a single line. Some Compound operators are:
SQL Special Operators
Special operators are used in SQL queries to perform specific operations like comparing values, checking for existence, and filtering data based on certain conditions.
SQL Special Operator Example
In this example, we will retrieve all records from the “employee” table where the “emp_id” column has a value that falls within the range of 101 to 104 (inclusive).
SQL Operators are used to perform various operations on the data using SQL queries. These operators simplify arithmetic, comparison , logical, and bitwise operations on the data.
In this tutorial, we have explained SQL operators in detail. We have explained different types of operators in SQL along with their definition and examples. Using SQL operators you can efficiently perform operations on data.
Similar Reads
- sql-operators
Please Login to comment...
Improve your coding skills with practice.
What kind of Experience do you want to share?
MySQL 5.7 Reference Manual Including MySQL NDB Cluster 7.5 and NDB Cluster 7.6
- Previous Logical Operators
- Home MySQL 5.7 Reference Manual Including MySQL NDB Cluster 7.5 and NDB Cluster 7.6
- Up Operators
- Next Flow Control Functions
12.4.4 Assignment Operators
Table 12.6 Assignment Operators
Assignment operator. Causes the user variable on the left hand side of the operator to take on the value to its right. The value on the right hand side may be a literal value, another variable storing a value, or any legal expression that yields a scalar value, including the result of a query (provided that this value is a scalar value). You can perform multiple assignments in the same SET statement. You can perform multiple assignments in the same statement.
Unlike = , the := operator is never interpreted as a comparison operator. This means you can use := in any valid SQL statement (not just in SET statements) to assign a value to a variable.
You can make value assignments using := in other statements besides SELECT , such as UPDATE , as shown here:
While it is also possible both to set and to read the value of the same variable in a single SQL statement using the := operator, this is not recommended. Section 9.4, “User-Defined Variables” , explains why you should avoid doing this.
This operator is used to perform value assignments in two cases, described in the next two paragraphs.
Within a SET statement, = is treated as an assignment operator that causes the user variable on the left hand side of the operator to take on the value to its right. (In other words, when used in a SET statement, = is treated identically to := .) The value on the right hand side may be a literal value, another variable storing a value, or any legal expression that yields a scalar value, including the result of a query (provided that this value is a scalar value). You can perform multiple assignments in the same SET statement.
In the SET clause of an UPDATE statement, = also acts as an assignment operator; in this case, however, it causes the column named on the left hand side of the operator to assume the value given to the right, provided any WHERE conditions that are part of the UPDATE are met. You can make multiple assignments in the same SET clause of an UPDATE statement.
In any other context, = is treated as a comparison operator .
For more information, see Section 13.7.4.1, “SET Syntax for Variable Assignment” , Section 13.2.11, “UPDATE Statement” , and Section 13.2.10, “Subqueries” .