# SQL

> The language you use to ask a database questions.

- Level: Basic
- Topics: Data, Software
- URL: https://tidbit.legios.com.ar/sql/
- In Spanish: [SQL](https://tidbit.legios.com.ar/es/sql/)

**SQL** (Structured Query Language, often pronounced 'sequel') is the language for talking to relational databases. You do not tell the database how to find the data, step by step; you describe what you want, and the database works out the fastest way to get it. That is why a few lines of SQL can answer a question over millions of rows.

A query reads almost like an English sentence: `SELECT name, city FROM customers WHERE country = 'AR' ORDER BY name;` asks for the name and city of every customer in Argentina, alphabetically. Other commands add rows (`INSERT`), change them (`UPDATE`) or remove them (`DELETE`). `JOIN` combines tables that point to each other, like orders with the customers who placed them, and `GROUP BY` summarizes, like total sales per month.

SQL dates from the 1970s and is still everywhere: PostgreSQL, MySQL, SQLite (the database inside most phones) and big analytics tools like Amazon Athena or a data warehouse. Each engine adds its own extras, called a dialect, but the core is the same, so learning it once pays off for decades. It is also one of the most useful skills outside engineering: analysts, product managers and marketers use it to answer their own questions.

## An analogy

Ordering at a restaurant. You say what you want ('the steak, medium, no fries'), not how to cook it; the kitchen (the database engine) decides the steps.

## Keep in mind

- SQL is declarative: you describe the result and the database decides how to get it.
- `SELECT` reads data; `INSERT`, `UPDATE` and `DELETE` change it.
- `JOIN` combines related tables and `GROUP BY` summarizes them.
- Every engine has its own dialect, but the basics work almost everywhere.

## Go deeper

- [What is SQL? (AWS)](https://aws.amazon.com/what-is/sql/)
- [The SQL language, PostgreSQL tutorial](https://www.postgresql.org/docs/current/tutorial-sql.html)
- [SQL on Wikipedia](https://en.wikipedia.org/wiki/SQL)

## Related terms

- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [Amazon Athena](https://tidbit.legios.com.ar/amazon-athena/): Run SQL directly on files sitting in S3, with no database to set up.
- [Data warehouse](https://tidbit.legios.com.ar/data-warehouse/): A database built for analysis: years of history, from many sources, in one place.
