Foundations › SQL › Foundations: Databases
️ Foundations: DatabasesWhat Is SQL and How to Read a Query
SQL (Structured Query Language) is the standard language for relational databases: we ask questions, add, change and delete data. Most of an analyst's work is asking, with SELECT.
| Family | Commands | Purpose |
|---|---|---|
| DQL | SELECT | Querying and reading data |
| DML | INSERT, UPDATE, DELETE | Changing data |
| DDL | CREATE, ALTER, DROP | Defining structure |
| DCL | GRANT, REVOKE | Permissions |
Shape of a query
It reads like a sentence: select name and city from customers where the city is Cairo, first 5 rows. Open in SQL Lab
Writing order is not execution order
We write SELECT first, but the database runs the query in a different order. Understanding this explains many errors you will meet later.
- FROM: pick the tables
- WHERE: filter rows
- GROUP BY: group
- HAVING: filter groups
- SELECT: choose columns
- ORDER BY: sort
- LIMIT: limit rows
SQL can even calculate without tables. Open in SQL Lab
For advanced readers Dialects
SQL is standard but each system differs a little (date and string functions, for example). In this path we use SQLite in your browser and point out differences in advanced boxes. Example: limiting rows is LIMIT in PostgreSQL, MySQL and SQLite, TOP in SQL Server, and FETCH FIRST in the standard and Oracle.
❓ Which part does the database run first?
The database starts with FROM to know the tables, then filters, then picks columns.
- SQL is the standard language for relational databases.
- SELECT is the analyst's core query command.
- Writing starts with SELECT but execution starts with FROM.
Want an expert to do it for you?
Gomaa Intelligence turns your data into clear reports and decisions. Tell us your problem and we will reply.