Home > Database > Mysql Tutorial > body text

How to query a column in mysql

WBOY
Release: 2022-01-18 15:57:16
Original
9314 people have browsed it

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".

How to query a column in mysql

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]
Copy after login

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 表名
Copy after login

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)
Copy after login

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!

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