📖 Scenario: You are working as a data assistant for a small bookstore. The store keeps track of books and their prices in a simple database table. You want to learn how to use SQL to manage this data.
🎯 Goal: Learn how to create a table, add data, and write a simple query to retrieve information using SQL.
📋 What You'll Learn
Create a table named books with columns id, title, and price
Insert three specific book records into the books table
Write a query to select all columns from the books table
Write a query to select only the title and price of books priced above 20
💡 Why This Matters
🌍 Real World
SQL is used to manage data in many businesses, like bookstores, to keep track of inventory and sales.
💼 Career
Knowing SQL helps you work with databases, a key skill for data analysts, developers, and many IT roles.
Progress0 / 4 steps
1
Create the books table
Write a SQL statement to create a table called books with three columns: id as an integer primary key, title as text, and price as a decimal number.
SQL
Hint
Use CREATE TABLE books (id INTEGER PRIMARY KEY, title TEXT, price DECIMAL(10,2)); to create the table.
2
Insert book records
Write three SQL INSERT INTO books statements to add these books exactly: (1, 'The Great Gatsby', 10.99), (2, 'War and Peace', 25.50), and (3, '1984', 15.00).
SQL
Hint
Use INSERT INTO books (id, title, price) VALUES (...); for each book.
3
Select all books
Write a SQL query to select all columns from the books table using SELECT * FROM books;.
SQL
Hint
Use SELECT * FROM books; to get all data.
4
Select books priced above 20
Write a SQL query to select only the title and price columns from books where the price is greater than 20.
SQL
Hint
Use SELECT title, price FROM books WHERE price > 20; to filter expensive books.
Practice
(1/5)
1. What is the main purpose of SQL?
easy
A. To design website layouts
B. To manage and manipulate data in databases
C. To write computer games
D. To create graphic designs
Solution
Step 1: Understand SQL's role
SQL is a language used to work with data stored in databases.
Step 2: Compare options
Only To manage and manipulate data in databases describes managing and manipulating data, which is what SQL does.
Final Answer:
To manage and manipulate data in databases -> Option B
Quick Check:
SQL = Data management [OK]
Hint: SQL is for data, not design or games [OK]
Common Mistakes:
Confusing SQL with programming languages
Thinking SQL is for web design
Mixing SQL with graphic tools
2. Which of the following is a correct SQL command to get data from a table named users?
easy
A. GET * FROM users;
B. FETCH ALL users;
C. SELECT * FROM users;
D. SHOW DATA users;
Solution
Step 1: Recall SQL syntax for retrieving data
The correct command to get all data from a table is SELECT * FROM table_name;.
Step 2: Match options with correct syntax
Only SELECT * FROM users; matches the correct SQL syntax for selecting data.
Final Answer:
SELECT * FROM users; -> Option C
Quick Check:
SELECT = retrieve data [OK]
Hint: Use SELECT to get data from tables [OK]
Common Mistakes:
Using GET instead of SELECT
Using FETCH or SHOW incorrectly
Missing FROM keyword
3. What will this SQL query return?
SELECT name FROM employees WHERE age > 30;
medium
A. All employee names with age less than 30
B. An error because of wrong syntax
C. All employee names regardless of age
D. All employee names with age greater than 30
Solution
Step 1: Understand the SELECT and WHERE clause
The query selects the name column from employees where the age is greater than 30.
Step 2: Interpret the condition
The condition age > 30 means only employees older than 30 are included.
Final Answer:
All employee names with age greater than 30 -> Option D
Quick Check:
WHERE age > 30 filters older employees [OK]
Hint: WHERE filters rows by condition [OK]
Common Mistakes:
Confusing > with <
Ignoring WHERE clause
Assuming all rows are returned
4. Identify the error in this SQL statement:
SELEC name FROM customers;
medium
A. Incorrect keyword 'SELEC' instead of 'SELECT'
B. Missing semicolon at the end
C. Table name 'customers' is invalid
D. No columns specified to select
Solution
Step 1: Check SQL keywords
The keyword to get data is SELECT, but here it is misspelled as SELEC.
Step 2: Verify other parts
The table name and column are valid, and the semicolon is optional in many systems.
Final Answer:
Incorrect keyword 'SELEC' instead of 'SELECT' -> Option A
Quick Check:
Correct spelling of SELECT is required [OK]
Hint: Check spelling of SQL keywords carefully [OK]
Common Mistakes:
Misspelling keywords
Assuming semicolon is mandatory
Confusing table and column names
5. You want to add a new user named 'Alice' with age 28 to a table users with columns name and age. Which SQL command should you use?
hard
A. INSERT INTO users (name, age) VALUES ('Alice', 28);
B. UPDATE users SET name = 'Alice', age = 28;
C. SELECT name, age FROM users WHERE name = 'Alice';
D. DELETE FROM users WHERE name = 'Alice';
Solution
Step 1: Understand the goal
You want to add a new row (user) to the table, so you need to insert data.
Step 2: Identify the correct command
INSERT INTO adds new rows; UPDATE changes existing rows; SELECT reads data; DELETE removes data.
Final Answer:
INSERT INTO users (name, age) VALUES ('Alice', 28); -> Option A
Quick Check:
INSERT adds new data [OK]
Hint: Use INSERT to add new rows [OK]
Common Mistakes:
Using UPDATE to add data
Confusing SELECT with INSERT
Deleting instead of adding
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.