FROM ;" syntax to query; if you want to query multiple fields, use commas "," between different field names Just separate them."/> FROM ;" syntax to query; if you want to query multiple fields, use commas "," between different field names Just separate them.">

Home >Database >Mysql Tutorial >How to query the data of a certain field in the database with mysql?

How to query the data of a certain field in the database with mysql?

青灯夜游
青灯夜游Original
2020-10-02 10:26:2717773browse

Mysql method of querying a certain field in the database: use the SELECT statement and use the "SELECT fb9e20f9179e11d29320f26fe3397d24 FROM d34fd6e2cbacaed4782dfb060b9009be;" syntax to query; if you want to query multiple fields, Different field names can be separated by commas ",".

How to query the data of a certain field in the database with mysql?

#In MySQL, you can use the SELECT statement to query data. Querying data refers to using different query methods to obtain different data from the database according to needs. It is the most frequently used and important operation.

The syntax format of SELECT is as follows:

SELECT
{* | <字段列名>}
[
FROM <表 1>, <表 2>…
[WHERE <表达式>
[GROUP BY <group by definition>
[HAVING <expression> [{<operator> <expression>}…]]
[ORDER BY <order by definition>]
[LIMIT[<offset>,] <row count>]
]

The meaning of each clause is as follows:

  • ##{*|b44f51d0b443c93502271d3d391e4df2 } A field list containing the asterisk wildcard character, indicating the name of the field to be queried.

  • ##05cee8b6ad5efd33489a0be0260a7bbc, a31a6b5c4a9ac86f75409c3950db0e23…, Table 1 and Table 2 represent the source of query data, which can be single or multiple.
  • WHERE ffbeece48539e6983ff3249db04f27c9 is optional. If selected, the query data must meet the query conditions.
  • GROUP BY3b26370eed070b4e2af74808aa8f2dee, this clause tells MySQL how to display the queried data and group it according to the specified field.
  • [ORDER BY0f5333100010744a1571ca8552350494], this clause tells MySQL in what order to display the queried data. The possible sorting is ascending order (ASC) and descending order (DESC ), which is ascending by default.
  • ##[LIMIT[ab76cfca1a1dc7ff1291dcdf873f72ec,]bc984d207842008469e14f06321b6461], this clause tells MySQL to display the number of queried data items each time.
Specified fields in the query table

The syntax format of a certain field in the query table is:

SELECT < 字段名 > FROM < 表名 >;

Example 3

Query the names of all students in the name column of the tb_students_info table. The SQL statement and running results are as follows.

mysql> SELECT name FROM tb_students_info;
+--------+
| name   |
+--------+
| Dany   |
| Green  |
| Henry  |
| Jane   |
| Jim    |
| John   |
| Lily   |
| Susan  |
| Thomas |
| Tom    |
+--------+
10 rows in set (0.00 sec)

The output shows all data under the name field in the tb_students_info table.

Use the SELECT statement to obtain data under multiple fields. You only need to specify the field name to be searched after the keyword SELECT. Different field names are separated by commas "," after the last field. There is no need to add commas, the syntax format is as follows:

SELECT <字段名1>,<字段名2>,…,<字段名n> FROM <表名>;

Example 4

Get the three columns of id, name and height from the tb_students_info table. The SQL statement and running results are as follows.

mysql> SELECT id,name,height
    -> FROM tb_students_info;
+----+--------+--------+
| id | name   | height |
+----+--------+--------+
|  1 | Dany   |    160 |
|  2 | Green  |    158 |
|  3 | Henry  |    185 |
|  4 | Jane   |    162 |
|  5 | Jim    |    175 |
|  6 | John   |    172 |
|  7 | Lily   |    165 |
|  8 | Susan  |    170 |
|  9 | Thomas |    178 |
| 10 | Tom    |    165 |
+----+--------+--------+
10 rows in set (0.00 sec)

The output shows all data under the three fields of id, name and height in the tb_students_info table.

Recommended tutorial:

mysql video tutorial

The above is the detailed content of How to query the data of a certain field in the database with mysql?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn