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
When you write buttons (input, button), you will f...
Analyze the production steps: 1. Prepare resource...
1. Form 1. The role of the form HTML forms are us...
Solution to forgetting MySQL password: [root@loca...
Table of contents 1. Overview 2. Download the Ngi...
Table of contents 1. Basic knowledge: 2. DHCP ser...
Preface My needs are syntax highlighting, functio...
Docker is an open source container engine that he...
This article records the installation and configu...
background In the early stages of learning Japane...
This article mainly records the effect of using j...
Transaction A transaction is a basic unit of busi...
Table of contents 1. Introduction 2. Configure My...
All blogs listed below are original and uniquely ...
Physical Structure of an InnoDB Index All InnoDB ...