MySql multi-condition query statement with OR keyword

MySql multi-condition query statement with OR keyword

The previous article introduced the MySql multi-condition query statement with the And keyword. The following article introduces the MySql multi-condition query statement with the OR keyword. Friends who are interested can learn together.

MySQL's multi-condition query with the OR keyword is different from the AND keyword. With the OR keyword, as long as the record meets any one of the conditions, it will be queried.

SELECT * | {field name 1, field name 2, ...}
FROM table name WHERE conditional expression 1 OR conditional expression 2 […… OR conditional expression n];

Query the names of students in the student table whose id field value is less than 15 or whose gender field value is nv

It can be seen that among the 5 records returned, 3 records have an id field value less than 15, or a gender field value of nv

Query the student table for records where the name field value starts with the character "h" or the grade field value is 100

It can be seen that the records that meet the conditions are queried

When OR and AND keywords are used together

The OR keyword and the AND keyword can be used together. Note that AND has a higher priority than OR.

Therefore, when the two are used together, the conditional expressions on both sides of AND should be calculated first, and then the conditional expressions on both sides of OR

Query the names of students in the student table whose gender field value is nv, or whose gender field value is na, and whose grade field value is 100

It can be seen

If the priority of AND is the same as or lower than that of OR, the AND operation will be executed last and the query result will return one record.

Here, three records are returned, indicating that the AND operation is executed first and the OR operation is executed later, that is, AND has a higher priority than OR.

The above is the MySql multi-condition query statement with OR keyword introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL learning prerequisites for querying data
  • Essential conditional query statements for MySQL database
  • MySQL conditional query and or usage and priority example analysis
  • Mysql multi-condition query statement with And keyword
  • How to use case when statement in MySQL to implement multi-condition query
  • A comprehensive summary of common operations of MySQL conditional query statements

<<:  Basic usage tutorial of IPTABLES firewall in LINUX

>>:  React hooks introductory tutorial

Recommend

js to achieve waterfall flow layout (infinite loading)

This article example shares the specific code of ...

Front-end development must learn to understand HTML tags every day (1)

2.1 Semanticization makes your web pages better u...

Detailed explanation of Mysql's concurrent parameter adjustment

Table of contents Query cache optimization Overvi...

VUE + OPENLAYERS achieves real-time positioning function

Table of contents Preface 1. Define label style 2...

The difference between float and position attributes in CSS layout

CSS Layout - position Property The position attri...

Detailed Example of CSS3 box-shadow Property

CSS3 -- Adding shadows (using box shadows) CSS3 -...

CentOS 7 builds hadoop 2.10 high availability (HA)

This article introduces how to build a high-avail...

CSS3 achieves flippable hover effect

CSS3 implements a flippable hover effect. The spe...

Solution for mobile browsers not supporting position: fix

The specific method is as follows: CSS Code Copy ...