Using TOP and LIMIT to Control Query Results
📖 Scenario: You work in a small bookstore's database team. The manager wants to see only a few top-selling books from the sales records to decide which books to promote.
🎯 Goal: Build SQL queries that show how to get the first 3 rows from a sales table using both TOP and LIMIT clauses, demonstrating their use in different databases.
📋 What You'll Learn
Create a table called
sales with columns book_title (text) and copies_sold (integer).Insert 5 rows with exact book titles and copies sold values.
Write a query using
TOP to select the first 3 rows ordered by copies_sold descending.Write a query using
LIMIT to select the first 3 rows ordered by copies_sold descending.💡 Why This Matters
🌍 Real World
Bookstores and many businesses often want to see only the top few records from large datasets to make quick decisions.
💼 Career
Knowing how to limit query results is essential for database developers and analysts to optimize performance and deliver relevant data.
Progress0 / 4 steps