Read data with SELECT
Choose columns and a source table to retrieve useful records.
- Write a basic SELECT query and choose only the columns you need.
A SELECT query describes the values to return, and FROM names the table to read. Use explicit column names in application queries so the result stays clear when a table changes.
1SELECT name, city
2FROM customers;
3
4SELECT order_id, total
5FROM orders;SQL keywords are commonly written in uppercase for readability, but most database systems accept them in lowercase too. The semicolon marks the end of a statement in many SQL tools.
Key takeaways
Write a basic SELECT query and choose only the columns you need.
Use table and column names that make the query easy to read.
Check which rows a query affects before relying on its result.
Lesson quiz
5 questions · pass with 4 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: write SQL queries
Write queries against small sample databases and run them locally in your browser. Each test starts from a fresh SQLite database.
Choose the columns you need
Return each customer’s name and email address, ordered by customer ID. Do not include the ID in the result.
- Names and emails
Sample tables and rows
Each test rebuilds an in-memory database for the selected dialect before running your query.
CREATE TABLE customers (customer_id INTEGER PRIMARY KEY, name TEXT, email TEXT); INSERT INTO customers VALUES (2, 'Ari Chen', 'ari@example.test'), (1, 'Sam Lee', 'sam@example.test');Using SQLite 3 (sql.js), an embedded database. Queries run locally in a worker against a fresh in-memory database for each test.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…