Skip to main content

What is SQL? Tutorial

Learn the basics of SQL.
Oct 2020  · 2 min read

SQL or structured query language is the native language for interacting with databases and is designed for exactly this purpose. It is a language of databases. A database models real-life entities like professors and universities by storing them in tables. Each table contains data from a single entity type. This reduces redundancy by storing entities only once. For example, there only needs to be one row of data containing a certain company's details. Lastly, a database can be used to model the relationship between entities.

If you would like to know how to learn the basics of SQL or become an expert, check out these blog posts:

Querying Databases

While SQL can be used to create and modify databases, this tutorial's focus will be on querying databases. A query is a request for data from a database table (or combination of tables). Querying is an essential skill for a data scientist since the data you need for your analyses will often live in databases.

In SQL, you can select data from a table using a SELECT statement. For example, the following query selects the name column from the people table:

FROM people;

In this query, SELECT and FROM are called keywords. In SQL, keywords are not case-sensitive, which means you can write the same query as:

select name
from people;

That said, it's good practice to make SQL keywords uppercase to distinguish them from other parts of your query, like column and table names.

It's also good practice to include a semicolon at the end of your query. This tells SQL where the end of your query is!

SQL Order of Execution

SQL Order of Execution

Note: Your query will always need a SELECT and a FROM statement (to identify which columns you want returned from which table)—the others are optional.

Example of SELECT

In the following example, you will SELECT the title column from the films table.

SELECT title
FROM films;

When we run the above code, it produces the following result:

Example of SELECT

Try it for yourself.

This content is taken from DataCamp’s Introduction to SQL course by Nick Carchedi.

Intermediate SQL Queries

4 hours
Master the basics of querying tables in relational databases such as MySQL, SQL Server, and PostgreSQL.
See DetailsRight Arrow
Start Course

SQL for Joining Data

5 hours
Join two or three tables together into one, combine tables using set theory, and work with subqueries in PostgreSQL.

Exploratory Data Analysis in SQL

4 hours
Learn how to explore what's available in a database: the tables, relationships between them, and data stored in them.
See all coursesRight Arrow

What is SQL Used For? 7 Top SQL Uses

Discover the uses of SQL in industries and specific jobs. Plus, learn why the SQL language is so versatile and in demand.
Natassha Selvaraj's photo

Natassha Selvaraj

11 min

SQL Window Functions Cheat Sheet

With this SQL Window Functions cheat sheet, you'll have a handy reference guide to the various types of window functions in SQL.
DataCamp Team's photo

DataCamp Team

10 min


COALESCE() is one of the handiest functions in SQL. Read this tutorial to learn how to master it.
Travis Tang 's photo

Travis Tang


FORMAT() is one of the most commonly used functions in SQL. Learn its main applications in this tutorial.
Travis Tang 's photo

Travis Tang


INSERT INTO lets you add data to your tables. Learn how to use it in this tutorial.
Travis Tang 's photo

Travis Tang


COUNT() lets you count the number of rows that match certain conditions. Learn how to use it in this tutorial.
Travis Tang 's photo

Travis Tang

See MoreSee More