We have learned about the addition, deletion, modification and query operations of the database before, but we only have a simple understanding of the query operations of the database. Let's follow the editor to learn other operations of database query records.
First we create a data table students. This operation is based on this data table. The data of this data table is as follows:
select distinct 字段1,字段2 from 表名;
Among them:
field: refers to the field that needs to be queried, such as in the data table id or age;
Table name: It is the data table we operate on, for example, I am operating the table students;
As long as any field between field 1 and field 2 is different, it will be selected. It is generally used for distinct
to filter only one field;
At the same time, this statement can also be used for a certain Query under these conditions, conditional query comparison symbols: =
,<
,>
,>=
, <=
,!=
and other comparison operators, you can use or
and
and other ## between multiple conditions #You can use in this statement.
select * from 表名 order by 字段名 asc;
select * from 表名 order by字段名 desc;
the default is ascending order when sorting.
limit at the end of the statement Number 1, number 2 are used to limit the number of queries. The number 1 represents which record to start fetching (starting from 0), and the number 2 represents how many records to fetch!
limit, then one record will be taken by default.
select sum(字段名) from 表名;
The sum of data can be achieved through sum.
select count(*|字段名) from 表名;
The counting of fields can be completed through count. The counting results of using * or field names are the same.
select max(字段名) from 表名;
max can find the maximum value in the data. In this data table, the maximum value is 40, so the output result is 40.
select min(字段名) from 表名;
min can find the minimum value in the data. In this data table, the minimum value is 10, so the output result is 10.
Recommended tutorial: mysql video tutorial
The above is the detailed content of How to perform data query in mysql. For more information, please follow other related articles on the PHP Chinese website!