grain
What exactly one row of a result, table or report represents, such as one order, one order line or one customer per month.
In more detail
Decide the grain before writing a query. A join to detail rows changes it, for example from one row per order to one row per item, which inflates counts unless you count distinct keys or aggregate before joining.
Related terms
- GROUP BY — The clause that splits rows into groups sharing the same values, so aggregates return one result per group.
- DISTINCT — A keyword that removes duplicate rows from a query's answer, or duplicate values inside an aggregate such as COUNT.
- Cartesian product — Every possible pairing of one item from each of two sets, so the number of pairs is the product of the two sizes.
- common table expression — A named intermediate result, written in a WITH clause before the main query, that later parts of the query can use like a table.
Taught in
- Grouping By Multiple Columns — PostgreSQL, Indexing & Relational Data Modeling
- Common Table Expressions — PostgreSQL, Indexing & Relational Data Modeling
- The N Plus One Problem — PostgreSQL, Indexing & Relational Data Modeling