EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MySQL Tutorial MySQL Operators
Secondary Sidebar
MySQL Tutorial
  • Basic
    • MySQL floor
    • MySQL DESCRIBE table
    • MySQL encryption
    • Introduction to MySQL
    • Is SQL Server a Database?
    • What is MySQL
    • Is MySQL Programming Language
    • MySQL Server
    • MySQL Community Server
    • How To Install MySQL
    • MySQL Versions
    • MySQL OpenSource
    • MySQL GUI Tools
    • MySQL Grant
    • MySQL Error 1064
    • MySQL Drop Database
    • MySQL not equal
    • MySQL SELECT INTO Variable
    • MySQL Commands
    • MySQL Operators
    • What is MySQL Schema
    • Wildcards in MySQL
    • MySQL Constraints
    • MySQL Administration
    • MySQL Data Type
    • MYSQL COMMIT
    • MySQL FORMAT
    • Timestamp to Date in MySQL
    • MySQL DATEDIFF
    • MySQL?Incremental Backup
    • MySQL JSON Data Type
    • MySQL ENUM
    • MySQL Default Port
    • Cheat Sheet MySQL
  • Queries
    • MySQL Queries
    • MySQL Query Commands
    • SELECT in MySQL
    • MySQL INSERT IGNORE
    • MySQL having
    • ORDER BY in MySQL
    • MySQL Cheat Sheet
    • MySQL ORDER BY Random
    • MySQL ORDER BY DESC
    • MySQL GROUP BY
    • MySQL GROUP BY Count
    • MySQL GROUP BY month
    • MySQL WHERE Clause
    • MySQL WITH
    • MySQL FETCH
    • MySQL DDL
    • MySQL DML
    • MySQL WHERE IN Array
    • MySQL Fetch Array
    • MySQL ISNULL
    • MySQL Index Types
    • Mysql? Export Schema
    • Amazon RDS for MySQL
    • MySQL greatest
  • Database
    • What is Data Modeling
    • What is Data Processing
    • DBMS Architecture
    • DBMS Keys
    • Careers in Database Administration
    • What is MySQL Database
    • MySQL Relational Database
    • How to Connect Database to MySQL
    • MySQL Database Repair
    • RDBMS Interview Questions
    • DBMS Interview Questions
  • Functions
    • MySQL Function
    • MySQL Aggregate Function
    • MySQL String functions
    • MySQL Date Functions
    • MySQL Window Functions
    • MySQL Math Functions
    • MySQL Boolean
    • Cursor in MySQL
    • Condition in MySQL
    • MySQL BETWEEN
    • Insert in MySQL
    • MySQL IFNULL()
    • MySQL TIMESTAMPDIFF()
    • MySQL COALESCE()
    • MySQL count()
    • MIN() in MySQL
    • MySQL Numeric
    • MySQL field()
    • MySQL FIND_IN_SET()
    • MySQL avg()
    • MySQL MAX() Function
    • MySQL BIN()
    • MySQL Concat
    • MySQL DECODE()
    • MySQL REGEXP_REPLACE()
    • MySQL Asynchronous
    • MySQL innodb_buffer_pool_size
    • MySQL key_buffer_size
    • MySQL TRUNCATE()
    • MySQL ROW_NUMBER()
    • NOT in MySQL
    • MySQL IN Operator
    • LIKE in MySQL
    • ANY in MySQL
    • MySQL NOT IN
    • MySQL CHECK Constraint
    • MySQL DISTINCT
    • MySQL ALL
    • MySQL Union
    • MySQL UNION ALL
    • MySQL EXISTS
    • MySQL ON DELETE CASCADE
    • MySQL REGEXP
    • MySQL Index
    • MySQL Add Index
    • MySQL REINDEX
    • MySQL UNIQUE INDEX
    • MySQL Clustered Index
    • MySQL? InnoDB Cluster
    • Table in MySQL
    • ALTER TABLE MySQL
    • MySQL Temporary Table
    • MySQL Clone Table
    • MySQL Repair Table
    • MySQL Lock Table
    • MySQL Optimize Table
    • TRUNCATE TABLE MySQL
    • MySQL Table Dump
    • MySQL Update Set
    • MySQL ALTER TABLE Add Column
    • MySQL RANK()
    • MySQL CTE
    • MySQL LAG()
    • MySQL GROUP_CONCAT()
    • MySQL EXTRACT()
    • MySQL REPLACE
    • MySQL AUTO_INCREMENT
    • MySQL SYSDATE()
    • MySQL NULLIF()
    • MySQL Substring
    • MySQL SUBSTRING_INDEX()
    • MySQL LOWERCASE
    • MySQL Row
    • MySQL NOW
    • MySQL CEIL
    • MySQL Alias
    • MySQL Trigger
    • MySQL SHOW Triggers
    • MySQL UPDATE Trigger
    • MySQL DELETE Trigger
    • MySQL AFTER UPDATE Trigger
    • MySQL Stored Procedure
    • ROLLUP in MySQL
    • MySQL? INSTR()
    • MySQL Subquery
    • MySQL Timestamp
    • MySQL? Hour()
    • MySQL MOD()
    • MySQL DATE_FORMAT()
    • ALTER Column in MySQL
    • MySQL Rename Column
    • MySQL Interval
    • MySQL CURDATE
    • MySQL BIT
    • MySQL Binlog
    • MySQL Average
    • MySQL TEXT
    • MySQL SHOW
    • MySQL Offset
    • MySQL Timezone
    • mysql_real_escape_string
    • MySQL Datetime
    • MySQL DATE_SUB()
    • MySQL FULLTEXT
    • MySQL DATE_ADD()
    • MySQL sum()
    • MySQL Merge
    • MySQL BigInt
    • MySQL ROUND
    • MySQL VARCHAR
    • MySQL Decimal
    • MySQL Limit
    • MySQL today()
    • MySQL WEEKDAY
    • MySQL Split
    • MySQL Create Function
    • MySQL BLOB
    • MySQL encode()
    • MySQL Primary Key
    • MySQL Foreign Key
    • Unique Key in MySQL
    • MySQL Drop Foreign Key
    • MySQL DROP TRIGGER
    • MYSQL Database
    • Delete Database MySQL
    • MySQL Root
    • MySQL Root Password
    • MySQL Client
    • MySQL Users
    • MySQL?User Permissions
    • MySQL add user
    • MySQL List User
    • MySQL Show Users
    • MySQL User Password
    • MySQL?Cardinality
    • MySQL Workbench
    • MySQL Backup
    • MySQL REVOKE
    • MySQL Dump
    • MySQL Cluster
    • MySQL Partitioning
    • MySQL Full Text Search
    • MySQL Admin Tool
    • MySQL Export Database
    • MySQL Export to CSV
  • Joins
    • Joins in MySQL
    • MySQL Outer Join
    • Left Outer Join in MySQL
    • MySQL Self Join
    • Natural Join in MySQL
    • MySQL DELETE JOIN
    • MySQL Update Join
    • MySQL Cross Join
  • Advanced
    • MySQL Formatter
    • MySQL TINYINT
    • MySQL Grant All Privileges
    • MySQL DROP TABLE
    • MySQL rename database
    • MySQL Flush Privileges
    • MySQL super Privilege
    • MySQL Character Set
    • MySQL Log File
    • MySQL Flush Log
    • Grant Privileges MySQL
    • MySQL WHILE LOOP
    • IF Statement in MySQL
    • MySQL CASE Statement
    • MySQL IF Function
    • MySQL IF EXISTS
    • MySQL UUID
    • Views in MySQL
    • MySQL Replication
    • MySQL Partition
    • Toad for MySQL
    • Navicat for MySQL
    • MySQL AES_Encrypt
    • MySQL Performance Tuning
    • MySQL Transaction
    • MySQL? sort_buffer_size
    • MySQL? Sync
    • MySQL? Query Cache
    • MySQL Collation
    • MySQL ODBC Driver
    • MySQL Partitioning
    • MySQL InnoDB
    • MySQL Float vs Decimal
    • MySQL Union vs Union All
  • Interview Questions
    • MySQL Interview Questions

Related Courses

MS SQL Certification Courses

Oracle Certification Courses

PL/SQL Certification Courses

MySQL Operators

By Priya PedamkarPriya Pedamkar

MySQL Operators

Introduction to MySQL Operators

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

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,992 ratings)

What are Operators in MySQL?

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

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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 right operand from the left operand a – b
* Multiplication of two operands a * b
/ Division of left operand by the right operand a / b
% Modulus – the remainder of the division of 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 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 left operand is less than that of a 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 left operand is greater than or equal to the right operand, the condition becomes true; if not then false. a >= b
<= If the value of left operand is less than or equal to the right operand, the condition becomes true; if not then false. a <= b
!< If the value of left operand is not less than the value of right operand, the condition becomes true; if not then false. a !< b
!> If the value of left operand is not greater than the value of right operand, 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 EMPLOYEE table as shown below to understand how to use the comparison operators as 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 the presence of a row in a table which satisfies a certain condition specified in the query.

OR

It is used to combine multiple conditions in a statement by using the WHERE clause.

AND

It allows the existence of 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 earlier to understand the usage of logical operators as shown 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

This has been a guide to MySQL Operators. Here we discuss different types of MySQL Operators like Arithmetic Operators, Comparison Operators, and Logical Operators with appropriate examples. You may also look at the following articles to learn more –

  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
Popular Course in this category
SQL Training Program (7 Courses, 8+ Projects)
  7 Online Courses |  8 Hands-on Projects |  73+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

MS SQL Training (16 Courses, 11+ Projects)4.9
Oracle Training (14 Courses, 8+ Projects)4.8
PL SQL Training (4 Courses, 2+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

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

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more