Back to articles list Articles Cookbook
7 minutes read

Learn SQL in 10 Minutes

SQL, or Structured Query Language, is a programming language used to communicate with databases. With SQL, you can retrieve data from a database, insert new data, and update or delete existing data. You can even modify the structure of a database: you can add or delete tables or columns and change the relationships between tables.

SQL is a standard, meaning it is a reference. Read about the history of the SQL standard in our article “The History of SQL Standards.”

In practice, each database system uses its own version of SQL, usually called an SQL dialect. SQL dialects are like dialects in the linguistics sense; they are mutually comprehensible. You don’t need to know every SQL dialect; their differences are very slight.

So don’t be afraid! With a strong knowledge of SQL, you can easily switch from one dialect to another. Read more about SQL dialects in our article “What Is a SQL Dialect, and Which One Should You Learn?

Do you want to know more about SQL? I recommend this excellent article by Kateryna Koidan, “What Is SQL?” Also, check out this best-seller course on LearnSQL.com, SQL Basics. If you are a complete beginner with no experience in programming or IT, this course is a perfect fit for you. It gives you a strong base to start your journey toward becoming an SQL expert.

Are you ready to learn SQL in 10 minutes?

What Is a Database?

In a nutshell, a database is a place where all your data is stored. Imagine you have your own business and need to store all the data related to your company in one place: client data, product data, sales data, etc.

If you own a small business, you may be able to do this with an Excel file or with an old-fashioned notebook. But if you run a business of significant size for a while, you can’t handle hundreds of thousands or millions of records with an Excel file. You need a database.

The Tables and the Structure of a Database

A key component of the database structure is the table. Each table is used to store data related to your needs. In our earlier example, we may define three tables: users, products, and sales.

A table contains columns that represent the characteristics of the data we store. A table like users may contain columns such as first_name, last_name, gender, SSN, etc.

A table has rows with data for different objects. If the users table has 1,000 rows, it represents 1,000 different users, one per row.

Conventionally, the first column of a table is a column called id that contains numbers to uniquely identify a row. In some cases, this value may be a key reference for other tables. Let’s see the following example:

Learn SQL in 10 Minutes

Marty McFly (ID 132) bought a hoverboard (ID 1254). Both values are referenced in the table sales, and the three tables are thus related. Also, Han Solo bought a Millennium Falcon, and Thanos bought Infinity Gems.

Examples of SQL Queries

In SQL, we communicate with a database using queries. An SQL query is a command to get data out of a database or to modify or delete data from a database.

SQL queries are designed to resemble an English sentence. They start with an action keyword (such as SELECT or UPDATE) and continue with additional information. SQL queries can get all the data from a database, filter data that satisfies certain criteria, and even perform computations on the data.

Let’s see real examples of SQL queries.

Getting all Data From a Table

This query:

SELECT * FROM table

selects all information – all columns and rows – from the table specified. The query starts with SELECT, to tell the database we want to select data. The asterisk (*) tells the database we want to select all columns from the table. After FROM, we put the name of the table from which we want to select. As a result, it selects all rows and all columns from the table.

Let’s try this with the example we saw earlier:

SELECT *
FROM users;

This gives the following:

idfirst_namelast_namessnphoneage
132MartyMcFly11111111112345678917
625HanSolo22222222298765432132
9745ThanosDione333333333458712961000

This is extremely simple, isn't it? The SQL syntax is easily understandable and intuitive.

Getting Some Columns From a Table

Let’s see another scenario.

Sometimes, we don’t want to see all the columns in the table. This query:

SELECT col1, col2 FROM table

allows us to select only the columns we want. After the SELECT clause, we list the names of the columns, separating them with commas. There is no limit to the number of columns; we may list just one or list all the columns of the table.

In this example, we need the id, the first name, and the last name from the table users:

SELECT
  id,
  first_name,
  last_name
FROM users;

It gives the following:

idfirst_namelast_name
132MartyMcFly
625HanSolo
9745ThanosDione

As in the earlier example, the query is very easy to understand.

Getting Some Columns and Some Rows From a Table

Great! Now, we know how to filter the columns of a table.

How about filtering rows? This is easy with a WHERE clause to set a condition for the query:

SELECT col1, col2 FROM table WHERE x = y;

Imagine we are given a user ID and need to search our database to retrieve the user. We can do this:

The condition id = 625 tells the database we are interested only in rows whose id column has the value 625. There’s only one row that satisfies this condition:

idfirst_namelast_name
625HanSolo

This is extremely powerful! Imagine you have a database with millions of entries. You can retrieve a user in milliseconds thanks to a short query!

Equality is not the only allowed operator inside a condition. We may use any of the following operators: <, <=, >, or >=, with a number. As an example, if we apply a filter to ssn like this:

SELECT
  id,
  first_name,
  last_name,
  ssn
FROM users
WHERE ssn >= 222222222;

It gives the following:

idfirst_namelast_name
625HanSolo

There is more we can do with a WHERE clause. We may create multiple conditions, thanks to the AND operator.

Imagine we want to filter our users for an age range. We can do so easily, like this:

SELECT
  id,
  first_name,
  last_name,
  age
FROM users
WHERE age >= 20 AND age <= 40;

This query finds users who are 20 years old or greater and at the same time are 40 or less. It gives the following result:

idfirst_namelast_nameage
625HanSolo32

Note that we can do the same thing more elegantly with the BETWEEN operator:

SELECT
  id,
  first_name,
  last_name,
  age
FROM users
WHERE age BETWEEN 20 AND 40;

Pretty easy, right? If you are not yet convinced, read the article by Jill Thornhill, “Is SQL Hard to Learn?

Interactive Courses From LearnSQL.com

Has this made you curious? Do you want to learn more?

You could read an SQL book or watch tutorials on YouTube. There is plenty of excellent material for beginners.

However, let’s be honest. When you start in the programming world, it is discouraging to read big books or watch unnecessarily long videos. You waste time switching between the book or video and your code editor. This is why I sincerely recommend you learn SQL online with interactive courses.

The online courses at LearnSQL.com are highly interactive. You learn new concepts and practice them immediately through small exercises. You are asked to write real SQL code and run it, and the platform tells you whether it is correct. Through many exercises, you become more confident and build solid SQL knowledge until you become an SQL expert.

And the best thing is that you don’t need to install ANYTHING on your computer. The only things you need are an Internet connection and a web browser! Look at the following screenshot:

Learn SQL in 10 Minutes

Overview of an interactive SQL course on LearnSQL.com

Amazing, isn’t it? On the left-hand side, you read the lesson; on the right-hand side, you edit the SQL code and see the results. It couldn’t be simpler!

Learn SQL Today!

That’s it – you can learn SQL in 10 minutes! I truly hope this article has motivated you to dive deeper into SQL concepts.

You can find on LearnSQL.com all the courses and resources you need to power your SQL career. If you’re a beginner, start with the SQL Basics course. It has 129 hands-on practical exercises to help you learn everything you need to get started with SQL.

So, what are you waiting for? Learn SQL and become an expert!