A database query is a way to ask the database for specific information.
- Usually done with SQL in relational databases.
- Queries help collect data for reports, dashboards, or analysis.
1. Collecting Specific Data
Example:
- Table: Sales → SaleID, Product, Amount, SaleDate
- Task: Find all sales in August 2025
SELECT Product, Amount, SaleDate
FROM Sales
WHERE SaleDate BETWEEN '2025-08-01' AND '2025-08-31';
- This query filters the data to show only August sales.
- You can use this data to create reports or analyze trends.
2. Summarizing Data
- Often, you want to aggregate data for reporting.
Example: Total sales per product
SELECT Product, SUM(Amount) AS TotalSales
FROM Sales
GROUP BY Product;
SUM(Amount) → adds up sales
GROUP BY Product → organizes results by each product
- Result: Easy to see which product made the most sales.