This article uses examples to illustrate the usage and priority of MySQL conditional query and or. Share with you for your reference, the details are as follows: Introduction to mysql and and orAND and OR can be used to combine two or more conditions in a WHERE clause. When using the OR keyword:
When using the and keyword:
Mysql and and or examplesThe table data needed in this example are as follows:
(1) AND condition query operator example: Use AND to display all data with title "php array" and category 1: SELECT * FROM ar WHERE title='php array' AND category='1' result:
(2) OR conditional operator example Use OR to display all data with title "java array" or seo_name "php": SELECT * FROM ar WHERE title='java array' OR seo_name='php' result:
(3) Combining AND and OR operators We can also combine AND and OR (using parentheses to form complex expressions): SELECT * FROM ar WHERE (title='java array' OR category='4') AND seo_name='php' result:
and and or precedenceYou can include any number of and and or operators in the where clause. Without any other symbols, such as parentheses, SQL will first execute the and condition and then the or statement, such as: select * from table from id=1 or id=2 and price>=10; /* http://www.manongjc.com/article/1439.html */ By default, this statement executes when id=2 and price is greater than or equal to 10, or when id=1. If you add brackets: select * from table from (id=1 or id=2) and price>=10; This statement executes when id=1 or id=2, and price is greater than or equal to 10. Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL transaction operation skills", "MySQL stored procedure skills", "MySQL database lock related skills summary" and "MySQL common function summary" I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: Using JavaScript to implement carousel effects
>>: Detailed explanation of fuser command usage in Linux
Table of contents 1. Pre-analysis 1. Variable pre...
The following graph shows how time-consuming it is...
Preface PIPE, translated as pipeline. Angular pip...
Preface Recently, I encountered a requirement. Du...
Install mysql5.7 under win, for your reference, t...
Table of contents Hbase installation and configur...
1. Modify the docker configuration file and open ...
1. Create a new rtmp directory in the nginx sourc...
Many times, we ignore the setting of the web page ...
Regardless of which version of Ubuntu, installing...
I took the bus to work a few days ago. Based on m...
If you are using Alibaba Cloud Server, you need t...
According to major websites and personal habits, ...
Generate a certificate chain Use the script to ge...
I saw this question in the SQL training question ...