Query normalized tables safely — Smart Study Module 7
Answer a focused business question without changing production records.
Outcomes
- Identify primary and foreign keys
- Filter with deterministic ordering
- Use read-only practice and correct dialect
Understand
The project kit includes setup.sql and a real SQLite database. SQL shown here uses SQLite syntax; SQL Server uses TOP instead of LIMIT and differs in date functions. Use a temporary learning database, never an employer connection.
SELECT names the columns to return, WHERE filters rows and ORDER BY defines their order. Without ORDER BY there is no guaranteed first result. A text date in ISO format sorts chronologically when stored consistently.
Use explicit columns in reports so an added source column does not silently alter an export. A row limit is useful for inspection, not a substitute for filters or access controls.
Follow along
- Open collections.sqlite in a SQLite tool, or run setup.sql in an empty SQLite database.
- Inspect four loans with SELECT.
- Filter January with a half-open date interval.
- Order payments by amount descending, then payment_id for ties.
Worked example
SELECT payment_id, amount FROM payments WHERE payment_date >= '2026-01-01' AND payment_date < '2026-02-01' ORDER BY amount DESC, payment_id LIMIT 1;
P002 is the largest January payment: ₹15,000.
Practice
Enter the largest January payment_id.
Create a free personalized study plan · Download project instructions
Interactive practice runs in your browser.