Home >Database >Mysql Tutorial >How to query a column in mysql
In mysql, you can use the SELECT statement to query the data of a column. The function of this statement is to query the data under specified conditions. The syntax is "select column name 1, column name 2... from table name".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
How to query a column in mysql
MySQL database uses the SQL SELECT statement to query data.
You can query data in the database through the mysql> command prompt window, or query data through PHP scripts.
Syntax
The following is the common SELECT syntax for querying data in a MySQL database:
SELECT column_name,column_name FROM table_name [WHERE Clause] [LIMIT N][ OFFSET M]
You can use one or more tables in the query statement, and use commas between tables. (,) split, and use the WHERE statement to set query conditions.
The SELECT command can read one or more records.
You can use an asterisk (*) to replace other fields, and the SELECT statement will return all field data of the table
You can use the WHERE statement to include any conditions.
You can use the LIMIT attribute to set the number of records returned.
You can use OFFSET to specify the data offset at which the SELECT statement starts to query. By default the offset is 0.
The syntax for querying a column is as follows:
select 列名1,列名2... from 表名
The example is as follows:
Query the data of the two fields t_name and t_birth in the test table, and match the row t_name=' name2':
mysql> select t_name,t_birth from test where t_name='name2'; +-------+------------+ | t_name | t_birth | +-------+------------+ | name2 | 2013-01-01 | +-------+------------+ 1 rows in set (0.00 sec)
Recommended learning: mysql video tutorial
The above is the detailed content of How to query a column in mysql. For more information, please follow other related articles on the PHP Chinese website!