📖 Scenario: You are working as a data assistant in a small bookstore. The store keeps track of books and their details in a database. You need to learn how to get information from this database to help customers find books.
🎯 Goal: Build a simple database query project that shows how to use the SELECT command to get information from a books table.
📋 What You'll Learn
Create a table called books with columns id, title, and author
Insert three specific books into the books table
Write a SELECT query to get all columns from the books table
Write a SELECT query to get only the title column from the books table
💡 Why This Matters
🌍 Real World
Bookstores, libraries, and many businesses use SELECT to find and show data they need quickly.
💼 Career
Knowing how to use SELECT is essential for database jobs, data analysis, and any role that works with data.
Progress0 / 4 steps
1
Create the books table
Write a SQL command to create a table called books with three columns: id as an integer primary key, title as text, and author as text.
SQL
Hint
Use CREATE TABLE books and define the columns with their types.
2
Insert three books into the books table
Write three SQL INSERT INTO books commands to add these books exactly: (1, 'The Hobbit', 'J.R.R. Tolkien'), (2, '1984', 'George Orwell'), and (3, 'To Kill a Mockingbird', 'Harper Lee').
SQL
Hint
Use INSERT INTO books (id, title, author) VALUES (...) for each book.
3
Select all columns from the books table
Write a SQL SELECT query to get all columns from the books table.
SQL
Hint
Use SELECT * FROM books; to get all columns.
4
Select only the title column from the books table
Write a SQL SELECT query to get only the title column from the books table.
SQL
Hint
Use SELECT title FROM books; to get only the titles.
Practice
(1/5)
1. Why is the SELECT command considered the most important in SQL?
easy
A. Because it retrieves data from the database for viewing.
B. Because it deletes data from the database.
C. Because it creates new tables in the database.
D. Because it updates existing data in the database.
Solution
Step 1: Understand the purpose of SELECT
The SELECT command is used to get data from tables so users can see it.
Step 2: Compare with other commands
DELETE removes data, CREATE makes tables, UPDATE changes data, but SELECT only shows data.
Final Answer:
Because it retrieves data from the database for viewing. -> Option A
Quick Check:
SELECT = retrieve data [OK]
Hint: SELECT is for viewing data, not changing it [OK]
Common Mistakes:
Confusing SELECT with DELETE or UPDATE
Thinking SELECT changes data
Mixing SELECT with CREATE commands
2. Which of the following is the correct basic syntax to select all columns from a table named employees?
easy
A. GET * FROM employees;
B. SELECT ALL FROM employees;
C. SELECT * FROM employees;
D. SHOW * FROM employees;
Solution
Step 1: Recall standard SELECT syntax
The correct syntax to get all columns is SELECT * FROM table_name;
Step 2: Check each option
SELECT * FROM employees; matches the correct syntax. Options A, B, and D use incorrect keywords.
Final Answer:
SELECT * FROM employees; -> Option C
Quick Check:
SELECT * FROM table = correct syntax [OK]
Hint: Use SELECT * FROM table to get all columns [OK]
Common Mistakes:
Using GET or SHOW instead of SELECT
Omitting FROM keyword
Using ALL without SELECT
3. Given the table products with columns id, name, and price, what will this query return?
SELECT name FROM products WHERE price > 100;
medium
A. All product names with price less than 100.
B. All product names with price greater than 100.
C. All product names regardless of price.
D. An error because price comparison is invalid.
Solution
Step 1: Understand the WHERE clause
The WHERE clause filters rows where price is greater than 100.
Step 2: Understand SELECT columns
Only the name column is selected, so the output shows product names matching the filter.
Final Answer:
All product names with price greater than 100. -> Option B
Quick Check:
WHERE price > 100 filters rows [OK]
Hint: WHERE filters rows; SELECT chooses columns [OK]
Common Mistakes:
Confusing greater than (>) with less than (<)
Expecting all columns instead of only name
Thinking query causes error
4. What is wrong with this SQL query?
SELECT name age FROM users;
medium
A. Missing WHERE clause.
B. Incorrect table name.
C. SELECT cannot have more than one column.
D. Missing comma between column names.
Solution
Step 1: Check column list syntax
Multiple columns must be separated by commas in SELECT.
Step 2: Identify the error
The query misses a comma between 'name' and 'age', causing syntax error.
Final Answer:
Missing comma between column names. -> Option D
Quick Check:
Columns need commas in SELECT [OK]
Hint: Separate columns with commas in SELECT [OK]
Common Mistakes:
Forgetting commas between columns
Assuming WHERE is always required
Thinking SELECT allows no commas
5. You want to see the names and salaries of employees who earn more than 5000 from the employees table. Which query correctly does this?
hard
A. SELECT name, salary FROM employees WHERE salary > 5000;
B. SELECT name salary FROM employees WHERE salary > 5000;
C. SELECT * FROM employees WHERE salary < 5000;
D. SELECT name, salary FROM employees;
Solution
Step 1: Identify needed columns and condition
You need name and salary columns, filtered by salary greater than 5000.
Step 2: Check each option
SELECT name, salary FROM employees WHERE salary > 5000; selects correct columns and filters salary > 5000. SELECT name salary FROM employees WHERE salary > 5000; misses comma, causing error. SELECT * FROM employees WHERE salary < 5000; filters salary less than 5000, wrong condition. SELECT name, salary FROM employees; selects all employees without filter.
Final Answer:
SELECT name, salary FROM employees WHERE salary > 5000; -> Option A
Quick Check:
SELECT columns WHERE condition = correct query [OK]
Hint: Use WHERE to filter rows, commas to separate columns [OK]
Common Mistakes:
Missing commas between columns
Using wrong comparison operators
Omitting WHERE clause when filtering
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.