EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials MySQL Tutorial MySQL Operators
 

MySQL Operators

Priya Pedamkar
Article byPriya Pedamkar

Updated May 9, 2023

MySQL Operators

 

 

Introduction to MySQL Operators

MySQL comes with special characters or words to perform certain operations. MySQL Operators are applied to the operands to carry out specific operations.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

What are Operators in MySQL?

Operators are used to specify a condition in a statement in MySQL. Below are the different types of operators used in MySQL.

1. Arithmetic Operators

In MySQL, arithmetic operators are used to perform the arithmetic operations as described below.

Arithmetic Operators in MySQL
Operator Description Example
+ Addition of two operands a + b
– Subtraction of the right operand from the left operand a – b
* Multiplication of two operands a * b
/ Division of the left operand by the right operand a / b
% Modulus – the remainder of the division of the left operand by the right a % b

The following are a few examples of operations using Arithmetic Operators.

Let us assume certain values for the below variables as

a = 10 , b = 5

  • a + b will give the result as 15.
  • a – b will give the result as 5.
  • a * b will give the result as 50.
  • a / b will give the result as 2.
  • a % b will give the result as 0.

2. Comparison Operators

The comparison operators in MySql are used to compare values between operands and return true or false according to the condition specified in the statement.

Comparison Operators in MySQL
Operator Description Example
> If the value of the left operand is greater than that of the value of the right operand, the condition becomes true; if not, then false. a > b
< If the value of the left operand is less than that of the value of the right operand, the condition becomes true; if not, then false. a < b
= If both the operands have equal value, the condition becomes true; if not, then false. a == b
!= If both the operands do not have equal value, the condition becomes true; if not, then false. a != y
>= If the value of the left operand is greater than or equal to the right, the condition becomes true; if not, then false. a >= b
<= If the value of the left operand is less than or equal to the right, the condition becomes true; if not, then false. a <= b
!< If the value of the left operand is not less than that of the right, the condition becomes true; if not, then false. a !< b
!> If the value of the left operand is not greater than that of the right, the condition becomes true; if not, then false. a !> b
<> If the values of two operands are not equal, the condition becomes true; if not, then false. a <> b

Let us take an example of the EMPLOYEE table, as shown below, to understand how to use the comparison operators stated above while performing MySQL queries.

ID NAME AGE SALARY
4 Sushma 32 35000.00
6 Ritu 23 23000.00
8 Amit 27 30000.00
11 Harish 35 35000.00
18 Pooja 28 29500.00

Let us use the different comparison operators to query the EMPLOYEE table, as shown below.

SELECT * FROM EMPLOYEE WHERE SALARY > 25000;
ID NAME AGE SALARY
4 Sushma 32 35000.00
8 Amit 27 30000.00
11 Harish 35 35000.00
18 Pooja 28 29500.00
SELECT * FROM EMPLOYEE WHERE SALARY = 35000;
ID NAME AGE SALARY
4 Sushma 32 35000.00
11 Harish 35 35000.00
SELECT * FROM EMPLOYEE WHERE SALARY < 35000;
ID NAME AGE SALARY
6 Ritu 23 23000.00
8 Amit 27 30000.00
18 Pooja 28 29500.00
SELECT * FROM EMPLOYEE WHERE SALARY != 30000;
ID NAME AGE SALARY
4 Sushma 32 35000.00
6 Ritu 23 23000.00
11 Harish 35 35000.00
18 Pooja 28 29500.00
SELECT * FROM EMPLOYEE WHERE SALARY <> 35000;
ID NAME AGE SALARY
6 Ritu 23 23000.00
8 Amit 27 30000.00
18 Pooja 28 29500.00

3. Logical Operators

The logical operators used in MySQL are shown below.

Logical Operators in MySQL

Operator

Description

BETWEEN

It is used to search within a set of values by the minimum value and maximum value provided.

EXISTS

It is used to search for a row in a table that satisfies a specific condition specified in the query.

OR

It combines multiple conditions in a statement by using the WHERE clause.

AND

It allows multiple conditions in an SQL statement’s WHERE clause.

NOT

It reverses the meaning of the logical operator with which it is used. (Examples: NOT EXISTS, NOT BETWEEN, NOT IN, etc.)

IN

It is used to compare a value in a list of literal values.

ALL

It compares a value to all values in another set of values.

ANY

It compares a value to any value in the list according to the condition specified.

LIKE

It uses wildcard operators to compare a value to similar values.

IS NULL

It compares a value with a NULL value.

UNIQUE

It searches for every row of a specified table for uniqueness (no duplicates).

Let us take the example of the same EMPLOYEE table as shown above to understand the usage of logical operators in the below queries.

SELECT * FROM EMPLOYEE WHERE AGE <= 25 AND SALARY >= 5000;
ID NAME AGE SALARY
6 Ritu 23 23000.00
SELECT * FROM EMPLOYEE WHERE AGE >= 25 OR SALARY >= 25000;
ID NAME AGE SALARY
4 Sushma 32 35000.00
8 Amit 27 30000.00
11 Harish 35 35000.00
18 Pooja 28 29500.00
SELECT * FROM EMPLOYEE WHERE AGE IS NOT NULL;
ID NAME AGE SALARY
4 Sushma 32 35000.00
6 Ritu 23 23000.00
8 Amit 27 30000.00
11 Harish 35 35000.00
18 Pooja 28 29500.00
SELECT * FROM EMPLOYEE WHERE NAME LIKE 'Am%';
ID NAME AGE SALARY
8 Amit 27 30000.00
SELECT * FROM EMPLOYEE WHERE AGE BETWEEN 25 AND 30;
ID NAME AGE SALARY
8 Amit 27 30000.00
18 Pooja 28 29500.00
SELECT NAME FROM EMPLOYEE WHERE EXISTS (SELECT NAME FROM EMPLOYEE WHERE SALARY > 25000);
NAME
Sushma
Amit
Harish
Pooja

Recommended Articles

We hope that this EDUCBA information on “MySQL Operators” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. IS MySQL is an OpenSource?
  2. How to use MySQL Commands
  3. Top 25 MySQL Query Commands
  4. Most Useful Cheat Sheet MySQL
  5. SQL Operators | Types with Code

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW