Databases and SQL in SQL
Topic 1 of 45 · 7 minFree lessonAlmost every app you use keeps its data in a database: your messages, your playlists, the products in a shop. A database is an organized store of data that a program can search and change quickly. SQL (Structured Query Language) is the language you use to ask a database questions. You'll hear it said as "S-Q-L" or "sequel".
In this course you'll use PostgreSQL, one of the most popular databases in the world. It runs right here in your browser.
Tables, rows and columns
A database keeps its data in tables. A table looks like a spreadsheet. Each column holds one kind of fact, like a name or a price. Each row is one thing, like one product.
This topic uses the database of a small plant shop. Its products table has a row for each product the shop sells.
Your first query
A query is a question you ask the database. SELECT * means "give me every column", and FROM products names the table.
SELECT * FROM products;The database answers with a table of its own: the columns, then one line per row. The last line counts the rows.
Asking another table
The shop has other tables too. Change the table name to see a different one. Here are the shop's customers.
SELECT * FROM customers;Some customers have no city. An empty space like that is a missing value, which you'll meet properly in a later topic.
How a query is written
SQL keywords like SELECT and FROM don't care about capitals, and a query can spread over several lines. Most people write keywords in capitals, so they stand out from table and column names. A semicolon ; marks the end of a query, so you can write several in a row.
select *from orders;Notice the customer_id column. Its numbers point at rows in the customers table, so order 1 belongs to customer 1, Ana Silva. You'll combine tables like this later in the course.
SELECT * FROM product;The table is called products, with an s. Check the name in the list of tables under the editor.
Try it yourself
Run the code in the editor and answer 8 practice questions on databases and sql. It's free, you only need an account.