What Is SQL?

Welcome to the SQL course! Almost every app keeps its data in a database: an online shop its products and orders, a bank its accounts and payments, a game its players and their scores. And to ask a database a question, programmers use SQL.

A database keeps its data in tables. A table looks like a spreadsheet: it has columns, each with a name, and rows, one for each thing the table describes. These are the first three rows of the table games of Pixel Shop, an online game shop:

idtitlegenrepricereleasedage_rating
1Dragon ForgeRPG402024-03-1416
2Pixel RacerRacing152023-07-023
3Moon FarmSimulation202022-11-183

Each row is one game, and each column says one thing about it: its title, its genre, its price in dollars, the day it came out and the age it is suitable from.

SQL (Structured Query Language, read as “S-Q-L” or “sequel”) is the language for working with databases. In SQL, you write what you want to know, not how to find it out. You don't write loops that go through the rows one by one. You say “show me the titles of the games that cost less than $20”, and the database works out how to find them.

SQL is about fifty years old, and it is still one of the most used programming languages in the world. There are many database systems: PostgreSQL, MySQL, Microsoft SQL Server, Oracle, SQLite. Each of them adds something of its own, but the basics of SQL are the same in all of them, and that is what you'll learn here. This course uses SQLite, a small database that runs right in your browser. It is also the most widespread database in the world: it is in every phone, in every web browser and in thousands of apps.

In this course, you'll work with the database of Pixel Shop. Its tables hold the shop's games, its customers, their orders and their reviews. Step by step, you'll learn to find what you need in them, to count and add up, to combine tables, and in the end, to change the data and to design tables of your own.

A question for the database is called a query. The simplest query shows a whole table:

SELECT * FROM games;

SELECT says that you want to see data, * (a star) means all columns, and FROM games says from which table. The semicolon ends the query. When you click Run, the database runs the query and shows its result, the rows it found, as a table under Results.

Next to Results, there's the tab Tables. It shows every table of the database with all its rows. Look there whenever you need to know what a table holds or what its columns are called. On a phone, you'll find both under Output.

Instructions

Write the query SELECT * FROM games; into the editor and click Run. The result has all 20 games of the shop, and it starts like this:

idtitlegenrepricereleasedage_rating
1Dragon ForgeRPG402024-03-1416
2Pixel RacerRacing152023-07-023
………………

On the next line, add a second query, which shows the whole table customers. Run the queries again: the result now has two tables, one for each query. The second one starts like this:

idnameemailcityjoinedreferred_by
1Emma Clarkemma.clark@mail.comLondon2023-01-15NULL
2Liam Turnerliam.t@mail.comManchester2023-02-031
………………

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

1/7