Explain the purpose of a CROSS JOIN and when it is useful, such as building a date spine or generating combinations

Quick Overview

Asks what a SQL CROSS JOIN returns and when that is useful in analytics, such as building a date spine to fill gaps in daily data or generating every combination of attributes. Tests join semantics and awareness of row explosion.

Explain the purpose of a CROSS JOIN and when it is useful, such as building a date spine or generating combinations

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Explain the purpose of a `CROSS JOIN`. When is it analytically useful, such as scaffolding a date spine or generating all combinations? ```hint Think about missing rows A daily sales table has no row for a store on a day it sold nothing. Ask how you would make that day show up in a report with a zero. ``` ### What a Strong Answer Covers - What a `CROSS JOIN` returns and how many rows it produces for inputs of N and M rows. - The scaffold pattern for a date spine: build every entity and date pair first, then attach the actual data and fill the gaps. - At least one other deliberate use, such as generating all attribute combinations or expanding rows with a numbers table. - The cost of row explosion and how an accidental cross join happens. ### Follow-up Questions - Why does a condition on the fact table belong in the `ON` clause of the left join, and what happens if you put it in `WHERE`? - The fact table has several rows per store and day. What goes wrong with the scaffold query, and how do you fix it? - How would you build a date spine in a database that has no `generate_series` function? - How does a `CROSS JOIN` compare with `INNER JOIN ... ON TRUE` and a comma-separated `FROM` list?

Overview: Asks what a SQL CROSS JOIN returns and when that is useful in analytics, such as building a date spine to fill gaps in daily data or generating every combination of attributes. Tests join semantics and awareness of row explosion.

PracHub logo
General
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Explain the purpose of a CROSS JOIN. When is it analytically useful, such as scaffolding a date spine or generating all combinations?

What a Strong Answer Covers Guidance

  • What a CROSS JOIN returns and how many rows it produces for inputs of N and M rows.
  • The scaffold pattern for a date spine: build every entity and date pair first, then attach the actual data and fill the gaps.
  • At least one other deliberate use, such as generating all attribute combinations or expanding rows with a numbers table.
  • The cost of row explosion and how an accidental cross join happens.

Follow-up Questions Guidance

  • Why does a condition on the fact table belong in the ON clause of the left join, and what happens if you put it in WHERE ?
  • The fact table has several rows per store and day. What goes wrong with the scaffold query, and how do you fix it?
  • How would you build a date spine in a database that has no generate_series function?
  • How does a CROSS JOIN compare with INNER JOIN ... ON TRUE and a comma-separated FROM list?