Timedora
Free Online Flashcard Deck

SQL Joins and Aggregation Free Online Flashcards

Study SQL Joins and Aggregation with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

How can you find keys that occur more than once?

Back

Group by the key and use HAVING COUNT(*) > 1 to find keys that occur more than once.

02
Front

Where should a right-table filter go to retain unmatched rows in a LEFT JOIN?

Back

Put the right-table condition in ON. The left join can then retain left-side rows with no qualifying match.

03
Front

How do you prevent two one-to-many child joins from inflating order totals?

Back

Aggregate each child table to one row per order_id, then join those summaries to orders. This prevents item-payment combinations from multiplying order-level measures.

04
Front

What does the intended grain of a query result specify?

Back

The grain states what one result row represents, such as one row per order. Define it before joining to predict whether matching rows will preserve or multiply rows.

05
Front

Why does joining child summaries grouped by order_id preserve one row per order?

Back

Each child summary has at most one row per order_id, so joining both summaries to orders preserves one row per order.

06
Front

What must a join include when related rows are identified by a composite key?

Back

Join on every column in the composite key. Omitting part of it can match unrelated rows.

07
Front

In a LEFT JOIN, how does COUNT(*) differ from COUNT(o.order_id)?

Back

COUNT(*) counts the preserved left-side row even without a match. COUNT(o.order_id), when order_id is non-nullable, counts matched orders.

08
Front

What does a LEFT JOIN retain when no right-side row matches?

Back

A LEFT JOIN returns every left-side row and fills right-side columns with NULL when no match exists.

09
Front

An order has three items and two payments. What can joining both child tables directly produce?

Back

The join can produce six rows: each of three items pairs with each of two payments. Order-level measures may be repeated and overcounted.

10
Front

What can a WHERE filter on the right table do after a LEFT JOIN?

Back

A WHERE condition on the right table generally removes rows where its value is NULL, excluding left-side rows without a qualifying match.

11
Front

What do GROUP BY and HAVING do, and what do they not determine?

Back

GROUP BY forms groups; HAVING filters those groups. Neither clause decides whether the chosen grain fits the business question.

12
Front

Does DISTINCT generally repair inflated aggregates from join multiplication?

Back

No. DISTINCT may hide symptoms or remove legitimate rows; it does not generally correct inflated aggregates caused by row multiplication.