What is SQL? Database basics
Question 1
Retrieve all the data in the users table.
What is a database?
A database is a system for organizing and storing data. It's similar to a spreadsheet, but the big difference is that it can search and manage millions of records at high speed.
In an online store like Amazon, for example, all the data about products, users, orders, and inventory is managed in a database.
What is SQL?
SQL (pronounced "S-Q-L" or "sequel") is a language for operating on databases. You can write "get data," "add data," "update data," and "delete data" operations in syntax that reads close to English.
SQL is an essential skill across many roles — web engineers, data analysts, marketers, and more. For example, if someone asks "pull up every customer whose spending last month was over $1,000," you can answer that instantly with just one or two lines of SQL.
The structure of a table
Data is stored in tables. A table is made up of columns and rows (records).
┌─────┬────────────┬──────────────────────────┬──────────┐
│ id │ name │ email │ city │ ← columns
├─────┼────────────┼──────────────────────────┼──────────┤
│ 1 │ 田中 太郎 │ tanaka@example.com │ 東京 │ ← records (rows)
│ 2 │ 鈴木 花子 │ suzuki@example.com │ 大阪 │
└─────┴────────────┴──────────────────────────┴──────────┘
Note: this site's sample database stores Japanese names and city names (like 田中 太郎 and 東京/Tokyo) as the actual data values, since it's the same live sample database used by the Japanese version of this site. You'll see these values in several exercises below.
id is the primary key that uniquely identifies each row. By assigning a number that's never duplicated, you can always pinpoint exactly "which row."
The tables used on this site
This site uses the following 4 tables for learning:
users— user table (15 records)products— product table (10 products)orders— order table (15 records)order_products— order line-item table (20 records)
People often think "SQL is a programming language," but strictly speaking it's a query language dedicated to data manipulation. There are no if-statements or for-loops — instead you write in a declarative style, describing "what data you want."
Try running the following SQL in the editor on the right:
SELECT * FROM users;