CoreTrail

Foundations

Understand tables, keys, data types, and how a query is evaluated.

Chapter overview 2 min read
On this page

Start with the grain

SQL becomes easier when you can name the input population and required output grain before choosing syntax. This chapter connects tables, keys, types, and logical query order so later joins and windows have a clear foundation.

Decision reference

Question Construct
Which rows are eligible? FROM, JOIN, WHERE
What is the reporting grain? GROUP BY and aggregates
Which groups qualify? HAVING
Which comparisons retain detail? Window functions
Which rows are displayed first? Final ORDER BY, LIMIT

In this chapter

Quick check

Take one query and say what one row represents after FROM, after GROUP BY, and in the final result. If the grain changes and you cannot explain why, revisit that step.

Type a concept, keyword, or function.