A: where
In the previous article, a rough introduction to where, but where can be followed by other conditions, now let's say one by one
1.between: Between a value of two
I created a table called person with id,name,age,post in it, and then inserted a few data, as shown in:
Then I want to change post in age 18-35 to ' rookie ', so I should run this line of code
The effect shown is:
2.in: Among a range of values
I want to change the post named Fangming and Lisi to "vegetable rookie", this time we need to use in, the code is as follows
The effect of the implementation is as follows:
3.is Null is empty
We sometimes need to do a series of operations on the values in the table that are empty, and we need to use the IS null operation, the code is as follows:
The effect of the implementation is as follows:
Because I did not transcode the name, so there was garbled, but the effect is to appear
Now that you have the is null, there is an operation that is not NULL, which operates on values that are not NULL, as follows:
The effect is as follows:
4.like: Fuzzy Query
We sometimes need to query the data at the beginning or end of a field, and this time we use the like, which is used in conjunction with%,
If I want to query the field that ends with ' Ming ' in name, the code is as follows
The effect is as follows:
Two. Nested queries
We sometimes need to make cross-table queries based on the same column names as two tables, which requires nested queries.
I have two tables, one is a student, one is a class, as shown in:
It can be seen that they all have a same column name CID, in fact, this column name can be different, but as long as it can be guaranteed by this column name query, that is, the same value can be
Now I want to check the students who belong to the class number of 52 students (a little bit around 0.0), the code is as follows:
May be a bit around, but carefully smoothed smooth or can understand, good, then we increase the difficulty, if I want to the student's class information and student information together print out, how to do it, it is obvious that nested query has not satisfied us, and see below:
Three: Correlation query
We need to use the correlation query, and its syntax is this
Select alias 1. Column name, alias 2. Column name from table name 1 alias 1, table name 2 alias 2 where alias 1. Same column
name = Alias 2. same column name;
I know you're dizzy, okay, let's go straight to the command line:
The effect is as follows:
is not very magical, and more magical, so out of the default is ascending, we can give him according to the CID in descending order, the code is as follows
You only need to follow the order by column named Ascending, order by column name desc to descending
When we query the target, nested queries and associated queries used together can often solve a lot of problems.
MySQL database three: command-line Appendix