官术网_书友最值得收藏!

Select statement in MySQL 8

The Select statement is used to retrieve data from single or multiple tables:

SELECT field 1, field 2, field 3 from table_name [WHERE Clause] [GROUP BY {col_name }] [HAVING where_condition] [ORDER BY {col_name} {ASC | DESC}, ...] [LIMIT{OFFSET M}{LIMIT N}]

This is the common syntax used to retrieve data from a single table:

  • Fields one and two are the column names of the table. To fetch all columns from the table, the * expression can be used.
  • table_name indicates the table name from where data needs to be retrieved.
  • The WHERE clause can be used to specify any condition in a single and multiple column.
  • The Group BY function is used with aggregate functions to group the result sets.
  • The HAVING clause is needed after GROUP BY to filter based on conditions for a group of rows or aggregates. If we use the HAVING clause without GROUP BY, it would act similarly to the WHERE clause.
  • The ORDER BY clause is used to sort the table result sets in ascending or descending order.
  • LIMIT is used to constrain the number of rows returned by the SELECT statement.

Let's go through each clause.

主站蜘蛛池模板: 化州市| 乌审旗| 河南省| 贡觉县| 全椒县| 潞西市| 马边| 许昌市| 铜山县| 曲水县| 鄂托克旗| 河津市| 淮滨县| 布拖县| 英吉沙县| 仁布县| 阳曲县| 苍南县| 寿宁县| 肥西县| 涿鹿县| 逊克县| 阿鲁科尔沁旗| 岢岚县| 塔河县| 平利县| 卓资县| 宁蒗| 白银市| 扎鲁特旗| 定安县| 西峡县| 白玉县| 大宁县| 汾阳市| 闽清县| 鄯善县| 舟曲县| 固阳县| 青州市| 兴安县|