Learn SQL
SQL is the standard language for storing, retrieving, and managing the data held inside relational databases.
What is SQL?
SQL stands for Structured Query Language. It is the language you use to talk to a relational database: to ask it questions, add new information, change what is already there, and remove what you no longer need. Almost every application that stores data, from a small website to a large banking system, relies on a database, and SQL is the common language used to work with those databases.
A relational database organizes information into tables, which are much like spreadsheets. Each table holds rows (also called records) and columns (also called fields). For example, a company might keep a Customers table where every row is one customer and the columns describe details such as name, city, and country. SQL lets you work with this data using short, readable commands instead of writing complex program code.
What can SQL do?
- Retrieve specific rows and columns from one or more tables
- Insert new records into a table
- Update the values stored in existing records
- Delete records that are no longer needed
- Create new databases and tables to hold data
- Control who is allowed to read or change the data
The most common thing you will do in SQL is read data with a query. A query is simply a request for information. The example below asks the database to return every column, for every row, from a table named Customers.
Example
SELECT * FROM Customers;You can also ask for just the columns you care about. Here we request only the customer name and the city they live in, which keeps the result focused and easy to read.
Example
SELECT CustomerName, City
FROM Customers;Throughout this tutorial we will use a small set of example tables, mainly Customers, Orders, and Products. Once you understand how to read data with SELECT, the rest of SQL builds naturally on top of it.
Exercise: SQL Introduction
What does the acronym SQL stand for?
Frequently Asked Questions
- Is SQL a programming language?
- SQL is a query language. You describe the data you want and the database works out how to fetch it, rather than writing step-by-step instructions. It is declarative, not procedural.
- How long does it take to learn SQL?
- A week or two to write SELECT, WHERE and JOIN queries confidently, which covers most day-to-day analysis. Query tuning, indexing and window functions take considerably longer.
- What is the difference between SQL and MySQL?
- SQL is the language. MySQL is a database that speaks it, as are PostgreSQL, SQL Server and SQLite. Learn SQL once and most of it transfers, with each database adding its own extensions.
- Do I need SQL for a data analyst job?
- Almost always. SQL is the most commonly listed requirement in data analyst postings, usually ahead of Python or a BI tool, because the data starts in a database.