How to query a certain field in the database in mysql: use the SELECT statement, use the “SELECT FROM ;” syntax to query; if you want to query multiple fields, use different field names Separate them with a comma “,”.
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 requirements, which is the most frequently used and most important operation.
The syntax of SELECT is as follows:
SELECT {* | } [ FROM , … [WHERE [GROUP BY [HAVING [{ }…]] [ORDER BY ] [LIMIT[,] ] ]
Among them, the meaning of each clause is as follows:
-
{*| } A field list containing asterisk wildcards, indicating the name of the field to be queried.
-
,
…, Table 1 and Table 2 indicate the source of query data, which can be single or multiple.
WHERE is optional, if you select this item, the query data must meet the query condition.
GROUP BY, this clause tells MySQL how to display the queried data and group it by the specified field.
[ORDER BY], this clause tells MySQL in what order to display the queried data, and the sorting that can be performed is ascending (ASC) and descending ( DESC), which is ascending by default.
[LIMIT[,]], this clause tells MySQL to display the number of data items queried each time.
Field specified in the query table
The syntax format of a field in the query table is:
SELECT FROM
;
Example 3
Query the names of all students in the name column in the tb_students_info table, the SQL statement and the 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 the 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 “,” and the last field There is no need to add a comma after it, the syntax format is as follows:
SELECT ,,..., FROM
;
Example 4
Get the three columns of id, name and height from the tb_students_info table, the SQL statement and the 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 the data under the three fields of id, name and height in the tb_students_info table.
Recommended tutorial: mysql video tutorial
The above is how mysql queries the data of a certain field in the database? For more details, please pay attention to other related articles on 1024programmer.com!
This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/how-does-mysql-query-the-data-of-a-field-in-the-database/