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

How to implement Vue timer

This article example shares the specific code of ...

Tips on making web pages for mobile phones

Considering that many people now use smartphones, ...

Linux remote control windows system program (three methods)

Sometimes we need to remotely run programs on the...

Why the explain command may modify MySQL data

If someone asked you whether running EXPLAIN on a...

7 skills that web designers must have

Web design is both a science and an art. Web desi...

Element-ui's built-in two remote search (fuzzy query) usage explanation

Problem Description There is a type of query call...

Useful codes for web page creation

<br />How can I remove the scroll bar on the...

MySQL column to row conversion tips (share)

Preface: Because many business tables use design ...

Detailed explanation of Linux file operation knowledge points

Related system calls for file operations create i...

About VUE's compilation scope and slot scope slot issues

What are slots? The slot directive is v-slot, whi...

Detailed introduction of Chrome developer tools-timeline

1. Overview Users expect the web applications the...

Introduction to Computed Properties in Vue

Table of contents 1. What is a calculated propert...