As shown below:
The result returned by the above statement is not what we want. analyze: The reason lies in the order of calculation. SQL prioritizes AND operators before OR operators. When SQL sees the above WHERE clause, the operators are incorrectly combined because AND has a higher precedence in the calculation order. The solution to this problem is to use parentheses to explicitly group corresponding operators. Please see the following SELECT statement SELECT prod_name,prod_price FROM products WHERE ( vend_id = 1002 OR vend_id = 1003 ) AND prod_price >= 10; Supplementary knowledge: Mysql | Combined where clause to filter data (AND, OR, IN, NOT) MySQL allows the use of multiple where clauses, and the combination of where clauses allows the use of two methods: AND and OR clauses. Operation symbols in the database: AND, OR, IN, NOT. AND :
OR :
IN : It is recommended not to use OR in clauses where IN can be used. IN has good performance and is easy to understand.
NOT: MySQL supports NOT only in the negation of IN, BETWEEN, and EXISTS clauses, which is different from most other databases that support various conditions.
Notice: In a clause that contains both AND and OR, MySQL prioritizes AND operations. It is generally recommended to use () to determine the processing order and eliminate ambiguity. for example:
The above article on solving the problems caused by the combination of AND and OR in MySQL is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to use Vue cache function
>>: A more elegant error handling method in JavaScript async await
In Google Chrome, after successful login, Google ...
1. Write the Dockerfile (1) Right-click the proje...
describe: fuser can show which program is current...
Today, when I was practicing with the Baidu page,...
Check the top 100 highest scores in game history ...
Preface When it comes to database transactions, a...
Preface NAT forwarding: Simply put, NAT is the us...
The previous article introduced how Vue can reali...
Preface Project requirements: Install the Docker ...
This article shares the specific code for JavaScr...
In HTML, <, >, &, etc. have special mean...
1. Enter the virtualization vcenter, log in with ...
Table of contents 1. Introduction 2. Main text 2....
1. Summary of location usage Location can locate ...
Starting from Elasticsearch 6.8, free users are a...