SQL
Structured Query Language
An entity-relationship diagram (ERD) is a common way to view how data is structured in a database.
Structured Query Language (SQL) is a language that allows us to access data stored in a database.
Types of SQL Databases
MySQL
Access
Oracle
Microsoft SQL Server
Postgres
Clauses
SELECT
: This clause specifies the columns from the data source that should be included in the query results.FROM
: This clause specifies the data source(s) that should be queried. This can be a table, a view, or the results of another query.WHERE
: This clause specifies conditions that must be met for a row to be included in the query results.GROUP BY
: This clause groups the rows of the query results by the values in one or more columns, allowing aggregate functions to be applied to each group.HAVING
: This clause is used to filter the groups in the query results, based on the values of aggregate functions applied to each group.ORDER BY
: This clause specifies the order in which the rows of the query results should be returned.LIMIT
: This clause limits the rows returned.
Query Execution Order
Order | Clause | Function |
---|---|---|
1 |
| Tables are joined to get the base data. |
2 |
| The base data is filtered. |
3 |
| The filtered base data is grouped. |
4 |
| The grouped base data is filtered. |
5 |
| The final data is returned. |
6 |
| The final data is sorted. |
7 |
| The returned data is limited to row count. |
It is common and best practice to capitalize all SQL commands, like SELECT
and FROM
, and keep everything else in your query lower case.
Resources
Last updated