Home > Database > Mysql Tutorial > body text

How to query multiple fields in mysql

青灯夜游
Release: 2022-01-04 14:23:58
Original
12604 people have browsed it

In mysql, you can use the SELECT statement to query multiple field data, the syntax is "SELECT field name 1, field name 2,..., field name n FROM data table name [WHERE clause];" ; Multiple field names need to be separated by English commas ",".

How to query multiple fields in mysql

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

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.

I want to query a specified field in the table

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

SELECT 列名 FROM 表名 [WHERE子句];
Copy after login

Example

Query the names of all students in the name column in 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)
Copy after login

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

Want to query multiple fields specified in the table

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

SELECT 字段名1,字段名2,…,字段名n FROM 表名 [WHERE子句];
Copy after login

Example

Get it from the tb_students_info table The three columns of id, name and height, 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)
Copy after login

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

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to query multiple fields in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!