Difference: 1. There is a difference in meaning, or refers to "or", and refers to "and"; 2. There is a difference in function, and must satisfy all conditions, while or means to satisfy Just one condition.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
When we query data, we will use conditions to filter the data to achieve the filtering effect, filter out unwanted data, and obtain what we need.
The most basic is the WHERE clause query: SELECT * FROM cs_user WHERE id = 10
In this way, we can query id = 10
The data. This is a multiple-choice question with only one conditional filter.
So in a table:
If I have data, I only need data with age between 18-20 (including 18 and 20). Then using the above WHERE clause and a single condition, it is difficult to obtain the effect we want. At this time, and and or come. Even beginners in English will understand the meaning of and and or. .
AND(and) and
OR(or) or
It is not difficult to understand it, but in actual application, just When you start learning, the logic may not be clear, which can be very troublesome. Let’s take a look:
AND: SELECT * FROM cs_user WHERE age >= 18 AND age
Picture:
Compare the cs_user table, greater than or equal to 18 and less than or equal to 20, exactly two pieces of data
OR: SELECT * FROM cs_user WHERE age >= 18 or age
Look at the picture:
Compare AND and OR: There is no difference in the way of writing
, they There are only two biggest differences:
1. The meaning itself, and (and), or (or)
2. The difference in function
and must meet all conditions , must satisfy age >= 18 and age
or, it only needs to satisfy one of them, and it will get Obtain the data of age >= 18, display it, and then obtain age
Succinctly speaking: and must meet all conditions; or only one condition can be met
[Related recommendations: mysql video tutorial]
The above is the detailed content of What is the difference between mysql or and and. For more information, please follow other related articles on the PHP Chinese website!