Tutorials

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:

SELECT name
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

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:

Try it for yourself.

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