seegongsik
Data

What is SQL

Say you are standing in front of a database packed with tables. How do you take out only what you want? You ask the database, clearly and precisely, the way you would ask a person: you choose which columns to see and state a condition for which rows to keep. The language used for asking like this is SQL.

01

Asking the database

Earlier we saw that a database is a warehouse full of tables, each with neat rows and columns. But among so many rows, how do you take out only the ones you want?
You ask, the way you would ask a person, except that the wording is fixed in advance. Turn a human request such as "Tell me the names of people aged twenty or more" into that fixed wording, and the database understands and answers.

"Tell me the names of people aged twenty or more"
SELECT _____ FROM people WHERE _____
Tap the human-word pieces to turn it into a question

Tap the pieces of the human request in turn to turn it into a query. Choose the column and the condition, and the fixed wording is built.

The human request has become a query. Look closely and it splits into two parts: one says which columns to see, the other which rows to keep.
Add which table to take them from with FROM, and the query is complete. It may look complicated, but inside it is simple. Let's start with choosing columns.

02

Choosing the columns to see: SELECT

A table has several columns, such as name, age, and city. But you do not always need every column; sometimes you only want the names.
Then you choose just the columns you want to see. Only the chosen columns remain and the rest are hidden. Choosing columns like this is called SELECT: it is the part that decides what the result shows.

Ana
24
Lima
Ben
17
Busan
Mei
31
Xian
Tap the heads of the columns you want

Tap the headers of the columns you want to see. Only the chosen columns remain and the others are hidden. Tap again to undo.

Only the columns you need remain, and the table is much easier to read. But choosing columns is sometimes not enough, because all the rows are still there.
Everyone shows up, whatever their age. We usually ask with a condition, such as "only people aged twenty or more." So this time, let's filter the rows.

03

Filtering rows with a condition: WHERE

Now it is the rows' turn. You do not need every row in the table. The rows you want share something in common, such as an age of twenty or more.
You write that shared feature as a condition. Rows that meet the condition stay, and rows that do not are left out. Filtering rows like this is called WHERE: it is the part that decides what to keep.

name
age
city
Ana
24
Lima
Ben
17
Busan
Mei
31
Xian
Leo
19
Oslo
Tap a condition to filter the rows

Tap a condition to apply it. Only the rows whose age meets the condition stay; the others fade out.

Only the rows that meet the condition remain, and the rest quietly dropped out. Now you have learned both skills: choosing columns and filtering rows.
But the real power comes when you combine them. Choose the columns you want to see while keeping only the rows you want, and you get a table with exactly what you need. Let's use both at once.

04

Combine them for a result table

Now let's use both skills at once. Filter the rows with the condition, and only the matching rows remain. Choose the columns you want from those rows, and only those columns show.
Where the chosen columns and the filtered rows meet, a small result table appears: the answer to your question, in the form of a table. A real database filters first and then picks columns, but whichever you think of first, the result is the same.

name
age
city
Ana
24
Lima
Ben
17
Busan
Mei
31
Xian
Leo
19
Oslo
Tap the two steps to combine them

Tap choose columns and filter by condition in turn. Combined, they produce a result table with only the matching rows and the chosen columns.

The answer you wanted came out as a table. Out of many rows and columns, a single query picked out exactly what was needed. The database does the picking for you, with no one scanning by eye.
It works the same way even when the table has a million rows. If there is an index, like the ones we saw earlier, the database uses it to find matching rows even faster. Write the query well, and the answer comes quickly.

05

Summary

In short: SQL is the language for asking a database questions. Choosing which columns to see is SELECT, and filtering which rows to keep is WHERE.
Combine them, and you get a result table that fits the condition exactly. Getting the answer you want as a table from a single query: that is the basis of SQL.

Tap the key points in order to review

Tap the key points in order to review. (SQL, the asking language → choose columns with SELECT → filter rows with WHERE → combine for a result table)

Now you know how to ask a database clear, precise questions: choosing the columns you want and filtering the rows to get back only the answer you need.
But so far we have dealt with only one table. In practice, information is often split across several tables, such as one for people and another for orders. The next lesson covers how to ask across several tables at once: the join.

In one lineSQL is the language for asking a database for what you want. You only need to say two things. First, you choose which columns to see: a table has several columns, and keeping only the ones you want to see is called SELECT. Next, you set a condition for which rows to keep: keeping only the rows that meet the condition, rather than every row, is called WHERE. When the chosen columns and the filtered rows meet, a small result table that fits the condition exactly comes out. Getting an answer back as a table from a single query is the basis of SQL.
← Data
Was this helpful? Support seegongsik