Introduction To MySQL Operators
MySQL is an RDBMS, and to access it many a time you would need to apply some filters or conditions to get specific data. To perform the same MySQL offers these operators which would help you in doing the same. These operations come in handy when you will be dealing with a very large database and there would be table mappings, it would be quite crucial to have a clear understanding of these operators to get the right information.
Various Operators In MySQL
In the broader sense below are the types of operators used in MySQL:
- Arithmetic Operators: These operations are used in numeric operations. These operators are simple and work just like basic algebra.
- Comparison Operators: Most commonly used operators in any SQL to query fields. These operators are widely used in data analysis.
- Logical Operators: As the name suggests when you need to apply logic, these logical operators would help you to do the same. The logic would be like, if the student’s height is greater than 5 ft “AND” student is Indian, he would like Cricket.
1. Arithmetic Operators
In MySQL, many times you would need to apply arithmetic operations in that case these arithmetic operators will come in handy in those cases.
Operator | What it does? |
+ | Adds two values (Operands). |
* | Multiplication operator multiplies two operands. |
– | Subtract operator, subtracts two operands. |
/ | Division operator divides two operands. |
% | Modulus operator, it gets a reminder after dividing one operand with another. |
Example:
X = 12
Y = 3
- X Y = 15
- X * Y = 36
- X – Y = 9
- X / Y = 4
- X % Y = 0
2. Comparison Operators
In MySQL, to query the data from the database sometime you would need to apply certain conditions or would need to compare the operands, and to do that these comparison operators would help you to do the same.
Operator | What it does? |
> | Left operand is greater than right operand. |
< | Left operand is smaller than left operand. |
!= | Left operand is not equal to right operand. |
== | Left operand is exactly equal to right operand. |
>= | Left operand is greater than or equal to right operand. |
<= | Left operand is less than or equal to right operand. |
!> | Left operand is not greater than right operand. |
!< | Left operand is not less than right operand. |
<> | Left operand is not equal to right operand. |
3. Logical Operators
Logical operators used frequently in MySQL are listed below:
Operator | What it does? |
OR | If one of the conditions satisfies, the statement will query. |
AND | If all the mentioned conditions are satisfied then only the query will execute. |
NOT | If the condition stated is not in the operands the query will execute. |
BETWEEN | This operator gives the flexibility to choose range for a query. |
EXISTS | This operator helps to point out if a specific condition exists before running the query. |
IN | This operator works the same as between operator in case of numerical inputs but it also provides flexibility for strings. |
LIKE | This operator helps a user to find a similar keyword in a table. |
ISNULL | To check if any fields are null in the table. |
UNIQUE | To get unique values from a table. |
Conclusion
MySQL is an RDBMS and there would be very large databases. To query some specific data MySQL offers some operators. In the above article, you have seen three types of operators: Arithmetic operator, Comparison operator, and Logical operator. These operators are used according to the need of the user also they are simple and can be understood by simple naming convention.
Recommended Articles
This is a guide to MySQL Operators. Here we discuss the introduction and the various operators in the MySQL respectively. You can also go through our other suggested articles to learn more –
Are you preparing for the entrance exam ?
Join our Data Science test series to get more practice in your preparation
View More