The SELECT Statement
The SELECT statement is used to retrieve data from the database and in general, it is the most frequently used SQL statement. and with the SQL statements, these are possible.
| |
Projection |
- Choose one or more columns in a table and return as the output. |
| |
Selection |
- Choose the rows in a table with different criteria to exact data and return as the output. |
| |
Joining |
- This is used to retrieve data stored in multiple tables by creating a “Join” between the tables. |
Basic SELECT Statement
A basic select statement should accompany with these two clauses.
| |
SELECT |
- Specifies the columns to retrieve |
| |
FROM |
- Specifies the name of the table to retrieve |
SQL Statement with optional clauses
In addition, these clauses can be added to retrieve specific data.
| |
WHERE |
- Specifies what should contain in the result fields. |
| |
GROUP BY |
- Specifies the criteria used to group the table into smaller groups. |
| |
HAVING |
- Specifies what should contain in Groups to include in results. |
| |
ORDER BY |
- Specifies the criteria used to sort the rows in the results. |
| |
LIMIT |
- Specifies how many records to retrieve from the result data set. |
Syntax
SELECT [Distinct | DISTINCTROW | ALL] select_expression, …
[FROM table_references
[WHERE where_definition]
[GROUP BY group_by_expression]
[HAVING where_definition]
[ORDER BY {unsigned_integer | col_name | formula} | ASC | DESC]
[LIMIT [offset] rows]