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] [GROUPBY {col_name }] [HAVINGwhere_condition] [ORDERBY {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_nameindicates the table name from where data needs to be retrieved.- The
WHEREclause can be used to specify any condition in a single and multiple column. - The
Group BYfunction is used with aggregate functions to group the result sets. - The
HAVINGclause is needed afterGROUP BYto filter based on conditions for a group of rows or aggregates. If we use theHAVINGclause withoutGROUP BY, it would act similarly to theWHEREclause. - The
ORDER BYclause is used to sort the table result sets in ascending or descending order. LIMIT...