Home > Database > Mysql Tutorial > What are the basic statements of mysql query

What are the basic statements of mysql query

下次还敢
Release: 2024-04-22 19:36:28
Original
1200 people have browsed it

The basic query statement of MySQL is SELECT, which is used to retrieve data from a database table. The SELECT syntax includes: SELECT [distinct] column name 1, column name 2, ...FROM table name WHERE condition HAVING grouping condition [LIMIT limit the number of rows].

What are the basic statements of mysql query

The basic statement of MySQL query

The basic statement of MySQL query isSELECT, use Used to retrieve data in selected databases and tables. The syntax format is as follows:

<code>SELECT [distinct] 列名1, 列名2, ...
FROM 表名
[WHERE 条件]
[GROUP BY 分组列]
[HAVING 分组条件]
[ORDER BY 排序列]
[LIMIT 限制行数]</code>
Copy after login

Among them:

  • SELECT: Specify the column to be retrieved.
  • DISTINCT (optional): Eliminate duplicate rows.
  • Table name: Specify the table to retrieve data from.
  • WHERE: Specify filter conditions and retrieve only rows that meet the conditions.
  • GROUP BY: Group the rows in the result set.
  • HAVING: Specify the filtering conditions for grouping.
  • ORDER BY: Specifies to sort the rows in the result set.
  • LIMIT: Limit the number of rows returned in the result set.

Example:

<code>SELECT name, age
FROM students
WHERE age > 18;</code>
Copy after login

This query will retrieve the names and ages of all students who are older than 18 years old from the students table.

The above is the detailed content of What are the basic statements of mysql query. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template