Home  >  Article  >  Database  >  How to query field value in mysql

How to query field value in mysql

青灯夜游
青灯夜游Original
2021-12-01 18:08:419196browse

Mysql method of querying field values: 1. Use the "SELECT * FROM table name;" statement to list the values ​​of all fields in the specified data table; 2. Use "SELECT field name FROM table name;" statement to list the values ​​of a specified field in a specified data table.

How to query field value in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Mysql method of querying field values ​​(data)

1. Query all field data in the table

Syntax:

SELECT * FROM 表名;

Example:

Query the data of all fields from the tb_students_info table

mysql> use test_db;
Database changed
mysql> SELECT * FROM tb_students_info;
+----+--------+---------+------+------+--------+------------+
| id | name   | dept_id | age  | sex  | height | login_date |
+----+--------+---------+------+------+--------+------------+
|  1 | Dany   |       1 |   25 | F    |    160 | 2015-09-10 |
|  2 | Green  |       3 |   23 | F    |    158 | 2016-10-22 |
|  3 | Henry  |       2 |   23 | M    |    185 | 2015-05-31 |
|  4 | Jane   |       1 |   22 | F    |    162 | 2016-12-20 |
|  5 | Jim    |       1 |   24 | M    |    175 | 2016-01-15 |
|  6 | John   |       2 |   21 | M    |    172 | 2015-11-11 |
|  7 | Lily   |       6 |   22 | F    |    165 | 2016-02-26 |
|  8 | Susan  |       4 |   23 | F    |    170 | 2015-10-01 |
|  9 | Thomas |       3 |   22 | M    |    178 | 2016-06-07 |
| 10 | Tom    |       4 |   23 | M    |    165 | 2016-08-05 |
+----+--------+---------+------+------+--------+------------+
10 rows in set (0.26 sec)

The results are displayed, using the "*" wildcard character When , all columns will be returned, and the data columns will be displayed in the order when the table was created.

Note: Generally, it is best not to use the wildcard character "*" unless you need to use all field data in the table. Although using wildcards can save time typing query statements, obtaining unnecessary column data often reduces the efficiency of the query and the application used. The advantage of using "*" is that when the names of the required columns are not known, they can be obtained via "*".

2. Query the specified field data in the table

Syntax:

SELECT 列名 FROM 表名;

Example:

Query the tb_students_info table The names of all students in the name column

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 the data under the name field in the tb_students_info table.

Note: You can use the SELECT statement to obtain data under multiple fields. You only need to specify the field name to be found after the keyword SELECT. Different field names are separated by commas ",", and the last one There is no need to add a comma after the field. The syntax format is as follows:

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

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to query field value in 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