TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL Logical Operators

Overview

In this tutorial, we will learn about MySQL Logical Operators with examples. We can combine several criteria with logical operators in the WHERE clause.

MySQL Logical Operators

Logical operators are used to combine multiple Boolean expressions. Logical operators in MySQL are as follows:

MySQL Logical Operator Description
AND Logical AND

Evaluates to true if both the two expressions evaluate to true.

In the older version we can also use the double ampersand (&&) operator instead of AND operator. Note that this will be deprecated in future releases.

OR Logical OR

Evaluates to true if either of the two expressions evaluates to true.

In the older version we can also use the double vertical pipes (|| )operator instead of OR operator. Note that this will be deprecated in future releases.

XOR Logical exclusive – OR

Evaluates to true if exactly one of the two expressions evaluates to true.

NOT Logical Negation

Evaluates to true if the expression evaluates to false.
We can also use an exclamation point !

Examples

AND Operator

In this example, we will use the Country table from the world MySQL database. We combine two conditions with the AND operator to retrieve rows from the table.

mysql> SELECT Name, Population
-> FROM Country
-> WHERE Continent =’North America’ AND Population > 8000000
-> ORDER BY Population;
+——————–+————+
| Name | Population |
+——————–+————+
| Haiti | 8222000 |
| Dominican Republic | 8495000 |
| Cuba | 11201000 |
| Guatemala | 11385000 |
| Canada | 31147000 |
| Mexico | 98881000 |
| United States | 278357000 |
+——————–+————+
7 rows in set (0.00 sec)

 

MySQL AND Operator

OR Operator

In this example, we will use the City table from the world MySQL database.

mysql> use world;
Database changed

mysql> SELECT Id, Name, District
-> FROM City
-> WHERE Name=’New York’ OR Name=’Jersey City’;
+——+————-+————+
| Id | Name | District |
+——+————-+————+
| 3793 | New York | New York |
| 3864 | Jersey City | New Jersey |
+——+————-+——-

MySQL OR Logical Operator

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ MySQL Comparison Operators› MySQL Insert Statement

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version