The standard query statements are as follows
Select Column name 1, column name 2, column name 3 from table name
The statement returns all rows of the corresponding column in the table
If you want to retrieve all the columns in a table, you can use the *
Select * from table name a
Because the table's non-code attributes allow duplication, it is found that there are duplicates in the search results, which can be filtered by distinct
Select distinct from table name F
You can use the limit clause if you are only interested in the first few rows of the search results
select column name from table name limit A, a, b
This means that the output starts from line A with a total of B line elements, and if you do not provide a then start at line 1th
If you need to sort the results of a search, you can use the ORDER BY clause
Select column name A, column name B from table name order by column name B; Select column name A, column name B from table name orderby desc;
That is, sorting according to column name B, plus desc for the reverse order, you can also follow the column name by commas separated by a second row sequence. For example, order by column name B desc, column name C
Data filtering via where
Select Column name from table name where name='a'
Note that if you need to sort the results, the where must precede the order by
Where-supported conditional actions
For example, the Select product from the products where the price between 5 and 10
Where also supports the determination of NULL values
Select product from products where attr is null
About where more advanced usage
where supports and and or operations between multiple conditions, but note that the and priority is higher than or, and if necessary, parentheses
The where also supports in and not
Select Student from stus where in (+) Select Student from stus wherenot in (18 ,)
It is worth noting that the first statement here matches age=18 or 20, and the second match is that age is neither equal to 18 nor equal to 20.
Instead of 18 to 20.
[Learning Record] MySQL primary query statement (select,where)