SQL course menu
What is SQL? A Beginner's Introduction to Databases and Queries
Learn what SQL is, what a database and a table are, and how a SQL query asks a database a question. Written for complete beginners.
On this page
Almost every app you use stores information somewhere: your messages, your orders, your playlists, your bank transactions. Most of that information lives in a database, and the most common way to talk to a database is a language called SQL.
In this lesson you will learn what SQL is, what a database looks like on the inside, and how to read your very first SQL query. You do not need any programming experience.
What does SQL stand for?#
SQL stands for Structured Query Language. People pronounce it either as letters, "S-Q-L", or as the word "sequel". Both are correct.
Let's break the name down:
- Query means question. Most of the time you use SQL to ask a database a question, such as "Which customers live in Mumbai?"
- Structured refers to the way the data is stored: in neat tables made of rows and columns.
- Language means it has its own words and rules, like any programming language. Luckily, SQL reads a lot like plain English.
What is a database?#
A database is an organised collection of data that a computer can search and update quickly. You can think of it as a set of very powerful spreadsheets that many people and programs can use at the same time without getting in each other's way.
The kind of database SQL works with is called a relational database. "Relational" just means the data is stored in tables, and tables can be connected (related) to each other.
Tables, rows, and columns#
Here is a small table called employees:
- A table stores one kind of thing. This one stores employees.
- A column is one piece of information about every item:
name,department,salary. - A row (also called a record) is one complete item. The row with
id2 is everything we know about Ravi.
The id column gives every row a unique number. A column like this is called a primary key. It lets the database tell rows apart even if two employees have the same name.
Your first SQL query#
Here is a real SQL query. Read it out loud and you will probably guess what it does:
SELECT name, salary
FROM employees
WHERE salary > 50000;It asks the database: "Give me the name and salary of every employee whose salary is more than 50,000." The database replies with a new, temporary table called a result set:
name | salary
-------+-------
Asha | 52000
Ravi | 78000
Meera | 81000Each part of the query has a job:
You will learn each of these keywords properly in the next lessons. For now, notice how readable it is.
What can you do with SQL?#
SQL is not only for reading data. With it you can:
- Read data: find, filter, sort, and summarise rows (
SELECT). - Change data: add new rows (
INSERT), edit rows (UPDATE), and remove rows (DELETE). - Design the database: create and change tables (
CREATE TABLE,ALTER TABLE). - Control access: decide who is allowed to see or change what.
Most beginners, analysts, and even many developers spend the majority of their time on number 1, which is why this course starts there.
SQL dialects: MySQL, PostgreSQL, SQLite and others#
There is one SQL standard, but many database products. The most popular include MySQL, PostgreSQL, SQLite, Microsoft SQL Server, and Oracle. Each one speaks a slightly different "dialect" of SQL.
The good news: the core of SQL (SELECT, WHERE, GROUP BY, JOIN, and so on) is almost identical everywhere. Everything in the fundamentals part of this course works in all of them. When a feature differs between databases, the lesson will point it out.
Who uses SQL?#
SQL is one of the most widely used skills in tech, and not only by programmers:
- Developers use it to store and load data for websites and apps.
- Data analysts use it to answer business questions, like "Which product sold best last month?"
- Data scientists use it to pull data before analysing it in Python.
- Product managers, marketers, and finance teams use it to get numbers without waiting for someone else.
Common mistakes#
Practice#
Practice exercise
Look at the employees table above and answer without running anything:
- How many rows does the table have?
- How many columns does it have?
- What do you think this query returns?
SELECT name
FROM employees
WHERE department = 'Engineering';Show hint
WHERE department = 'Engineering' keeps only the rows where the department column says Engineering. SELECT name then shows just the name column of those rows.
Show solution
- 4 rows, one for each employee.
- 4 columns:
id,name,department,salary. - The names of the two engineers:
name
------
Ravi
MeeraKey takeaway#
Next, you will learn the most important SQL statement of all: SELECT.
Finished this lesson?