This may be an issue that is easily overlooked. First of all, we must be clear: select * from table where condition 1 AND condition 2 OR condition 3 Equivalent to select * from table where (condition 1 AND condition 2) OR condition 3 select * from table where condition 1 AND condition 2 OR condition 3 AND condition 4 Equivalent to select * from table where (condition 1 AND condition 2) OR (condition 3 AND condition 4) Let’s take a look at some examples to understand more deeply: Test table data: SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for book -- ---------------------------- DROP TABLE IF EXISTS `book`; CREATE TABLE `book` ( `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, `author` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, `price` decimal(10, 2) DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of book -- ---------------------------- INSERT INTO `book` VALUES (1, 'PHP', 'mate', 21.00); INSERT INTO `book` VALUES (2, 'JAVA', 'kaven', 23.00); INSERT INTO `book` VALUES (3, 'JAVA Advanced', 'loose', 45.00); INSERT INTO `book` VALUES (4, 'GO', 'jim', 46.00); INSERT INTO `book` VALUES (5, 'GO Design', 'json', 76.00); INSERT INTO `book` VALUES (6, 'PHP Advanced Programming', 'bate', 67.00); INSERT INTO `book` VALUES (7, 'Python', 'jim', 66.00); INSERT INTO `book` VALUES (8, 'Python Design', 'mali', 54.00); INSERT INTO `book` VALUES (9, 'GO Programming', 'kaven', 86.00); INSERT INTO `book` VALUES (11, 'Python3', 'jim', 55.00); SET FOREIGN_KEY_CHECKS = 1; Query method 1: SELECT * FROM book WHERE author='jim' OR author='json' AND name='PHP'; The above query is equivalent to: SELECT * FROM book WHERE author='jim' OR (author='json' AND name='PHP'); Then the above query results are easy to understand. Query method 2: SELECT * FROM book WHERE name='PHP' AND author='jim' OR author='json'; The above query is equivalent to: SELECT * FROM book WHERE (name='PHP' AND author='jim') OR author='json'; Query method 3: SELECT * FROM book WHERE name='GO' AND (author='jim' OR author='json'); This is easy to understand. Understand the precedence of and or. These queries are not so "confusing to understand". This is the end of this article about the priority analysis of and or queries in MySQL. For more relevant MySQL and or query content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: abbr mark and acronym mark
>>: The problem of form elements and prompt text not being aligned
For individual webmasters, how to make their websi...
Brief review: Browser compatibility issues are of...
I always feel that translate and transition are v...
Table of contents Preface step Preface Today I fo...
Table of contents 1. Sorting function 2. Prepare ...
This is my first time using the element framework...
1.Jenkins installation steps: https://www.jb51.ne...
Table of contents View Disk Usage Disk Cleanup (D...
Table of contents 1. Introduction 2. Main text 2....
There are many purposes for exporting MySQL data,...
Clustering is actually relative to the InnoDB dat...
Detailed explanation of the role of static variab...
template <el-table :data="dataList"&...
Table of contents background Question 1 Error 2 E...
What is a mirror? An image can be seen as a file ...