0
0
MySQLquery~30 mins

Column aliases in MySQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Column Aliases in SQL Queries
📖 Scenario: You work at a small bookstore. The store keeps a database of books with columns for the book's title, author, and price. You want to create a report that shows the book title and price, but with clearer column names for the report.
🎯 Goal: Create a SQL query that selects the title and price columns from the books table, but uses column aliases to rename title as Book_Title and price as Book_Price.
📋 What You'll Learn
Create a table called books with columns title (VARCHAR), author (VARCHAR), and price (DECIMAL).
Insert three specific book records into the books table.
Write a SELECT query that uses column aliases to rename title as Book_Title and price as Book_Price.
Use the exact alias names Book_Title and Book_Price in the query.
💡 Why This Matters
🌍 Real World
Column aliases help make SQL query results easier to read and understand, especially when generating reports or exporting data.
💼 Career
Using column aliases is a common skill for database analysts, developers, and anyone working with SQL to present data clearly.
Progress0 / 4 steps
1
Create the books table and insert data
Create a table called books with columns title as VARCHAR(100), author as VARCHAR(100), and price as DECIMAL(5,2). Then insert these three rows exactly: ('The Great Gatsby', 'F. Scott Fitzgerald', 10.99), ('1984', 'George Orwell', 8.99), and ('To Kill a Mockingbird', 'Harper Lee', 7.99).
MySQL
Need a hint?

Use CREATE TABLE to define the table and INSERT INTO to add rows.

2
Write a basic SELECT query
Write a SELECT query that selects the title and price columns from the books table without any aliases.
MySQL
Need a hint?

Use SELECT title, price FROM books; to get the columns.

3
Add column aliases to the SELECT query
Modify the SELECT query to use column aliases. Rename title as Book_Title and price as Book_Price using the AS keyword.
MySQL
Need a hint?

Use AS to rename columns like title AS Book_Title.

4
Complete the query with aliases and order by price
Add an ORDER BY clause to the query to sort the results by Book_Price in ascending order. Use the alias Book_Price in the ORDER BY clause.
MySQL
Need a hint?

Use ORDER BY Book_Price ASC to sort by the alias.