Gomaa Intelligence.Data Hub
عربي

Foundations › SQL › Foundations: Databases

️ Foundations: Databases

What Is SQL and How to Read a Query

Lesson 4 / 14· 6 min

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.

FamilyCommandsPurpose
DQLSELECTQuerying and reading data
DMLINSERT, UPDATE, DELETEChanging data
DDLCREATE, ALTER, DROPDefining structure
DCLGRANT, REVOKEPermissions

Shape of a query

▶ Try it yourself

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.

  1. FROM: pick the tables
  2. WHERE: filter rows
  3. GROUP BY: group
  4. HAVING: filter groups
  5. SELECT: choose columns
  6. ORDER BY: sort
  7. LIMIT: limit rows
▶ Try it yourself

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?

Summary
  • 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.

Get your data analyzed by an expert ↗