
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Priority of AND and OR operator in MySQL select query?
The AND has the highest priority than the OR operator in MySQL select query.
Let us check how MySQL gives the highest priority to AND operator.
The query is as follows
mysql> select 0 AND 0 OR 1 as Result;
The following is the output
+--------+ | Result | +--------+ | 1 | +--------+ 1 row in set (0.00 sec)
If you are considering the OR operator has the highest priority then MySQL will wrap up the above query like this.
The query is as follows
select 0 AND (0 OR 1) as Result
First, solve the 0 OR 1, this will give result 1. After that 0 and 1 will give the result 0.
But the above case is not fine because we are getting 0 and the output is 1. So, in the above query, AND gets the highest priority than OR to get result 1.
The query is as follows
select 0 AND 0 OR 1 as Result
First, solve AND operator first. 0 AND 0 give result 0.
After that 0 OR 1 gives result 1.
Now we are getting the exact output.
- Related Articles
- MySQL query to return multiple row records with AND & OR operator
- Fetch a specific record using a single MySQL query with AND & OR operator
- Select query using MySQL IN() and avoid sorting in it
- MySQL UNION SELECT and IN clause in a single query
- How to order and select query with conditions in MySQL?
- Implement SELECT LIKE and CHAR_LENGTH() in a single MySQL query
- MySQL query with OR & AND conditions
- MySQL query to select maximum and minimum salary row?
- MySQL select and insert in two tables with a single query
- Select multiple sums with MySQL query and display them in separate columns?
- Select first word in a MySQL query?
- Select query with regular expression in MySQL
- Insert with a Select query in MySQL
- MySQL query to select records with a particular date and time?
- MySQL SELECT query to return records with specific month and year

Advertisements