Questions / Quant development, SQL & data pipelines

Know a join’s cardinality

Foundation, about 6 minutes. Question D031.

A join key appears twice in table A and three times in table B. An inner equijoin has no further condition. How many joined rows does that key produce?

Answer it in the app It's free. You get hints, a second try if you miss, and a follow-up question.

Show the answer and worked solution

Answer: 6 rows

  1. Fix one A row: it matches all three B rows carrying the key.
  2. There are two such A rows, so total matching pairs are 2 × 3=6.
  3. An equijoin does not select just one matching row or remove duplicates unless the query says to do so.

Interview shortcut. Inner join rows per key = left count × right count.

Takeaway. The data relationship determines join cardinality.

In the app this has a follow-up where one thing about the setup changes. Try the follow-up.

More sql & data pipelines questions