0
0
MySQLquery~30 mins

Why ordering organizes results in MySQL - See It in Action

Choose your learning style9 modes available
Why ordering organizes results
📖 Scenario: You work at a bookstore that keeps track of book sales in a database table called sales. Each sale record has the book_title and the copies_sold. You want to see the sales data sorted to understand which books sell the most and which sell the least.
🎯 Goal: Build a SQL query that retrieves all sales records and orders them by the number of copies sold, from highest to lowest.
📋 What You'll Learn
Create a table called sales with columns book_title (VARCHAR) and copies_sold (INT).
Insert exactly these three rows into sales: ('The Alchemist', 150), ('1984', 200), ('The Hobbit', 120).
Write a SQL query that selects all columns from sales and orders the results by copies_sold in descending order.
Ensure the final query uses ORDER BY copies_sold DESC.
💡 Why This Matters
🌍 Real World
Ordering query results helps businesses quickly see top-selling products or important data sorted by priority.
💼 Career
Database developers and analysts use ORDER BY to organize data reports and dashboards for decision making.
Progress0 / 4 steps
1
Create the sales table and insert data
Create a table called sales with columns book_title as VARCHAR(100) and copies_sold as INT. Then insert these exact rows: ('The Alchemist', 150), ('1984', 200), and ('The Hobbit', 120).
MySQL
Need a hint?

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

2
Set up the SELECT query
Write a SQL query that selects all columns from the sales table using SELECT * FROM sales.
MySQL
Need a hint?

Use SELECT * FROM sales; to get all rows and columns.

3
Add ordering by copies_sold descending
Modify the SELECT query to order the results by copies_sold in descending order using ORDER BY copies_sold DESC.
MySQL
Need a hint?

Use ORDER BY copies_sold DESC to sort from highest to lowest.

4
Complete the query with ordering
Ensure the final query is SELECT * FROM sales ORDER BY copies_sold DESC; to organize the sales results from most to least copies sold.
MySQL
Need a hint?

Check that your query orders by copies_sold descending.