📜 Module: Limiting & Sorting Data with SQL


Objective:

🔍 Learn how to limit the number of rows retrieved and sort them in a desired order using SQL.


Introduction:

💡 Imagine a packed supermarket aisle. Sometimes you only want to pick up a few items quickly, and that's where LIMIT comes into play. Other times, you might want the items to be arranged in a specific order, such as by expiry date or brand. In SQL, these commands help you view your data in a similar fashion.


Main Content:

📌 Limiting Data with LIMIT

The LIMIT clause restricts the number of rows you retrieve.

📋 Sample Question: "From our store's database, can you fetch the names and prices of just the first 5 products?"

SELECT product_name, price FROM products LIMIT 5;

Screenshot 2023-09-17 at 4.47.16 PM.png


📌 Sorting Data with ORDER BY

The ORDER BY clause allows you to sort results based on specific columns.

📋 Sample Question: "Can you show products sorted by brand name in alphabetical order and display their names and brands?"