Learn with Abdou

INTERACTIVE LECTURES

Answer questions across tables

Guided class activity · apply the ideas from the full SQL lessons.

Preparing for Lab 8 · After practice, try the team challenge.

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

Join on a relationship, not a coincidence

Step 1 of 12 · Database: Pixar & Box Office

READ & UNDERSTAND

INNER JOIN returns matching pairs. The ON condition expresses the relationship: movies.id matches boxoffice.movie_id. Similar row positions or similar-looking names are not a relationship.

Before running, predict the unit and possible multiplicity of the result. A JOIN can duplicate a source fact even when the SQL is valid.

Worked example
SELECT m.title, b.rating FROM movies AS m JOIN boxoffice AS b ON b.movie_id = m.id ORDER BY m.id;

The ON condition pairs a movie with its related box-office row using the identifier. Aliases m and b shorten references without changing the matching rule.

The output is one row per matched pair. Check uniqueness of movie_id in boxoffice before treating it as one row per movie in a different dataset.

Your question

Return title, domestic_sales, and international_sales for each matched movie, ordered by movie id.

Explain your evidence

What evidence would you collect before assuming there is exactly one sales record per movie?

Try a query to unlock the worked-answer discussion.

Loading…
Table & column names only · ↑ ↓ choose · Tab insert · Esc dismiss

CURRENT DATABASE

Quick schema · Pixar & Box Office

Press Esc or click outside to return to your query. PK = primary key · FK = declared foreign key.

This database has no tables yet. Create a table, then reopen the schema to see its columns.

Control Space also opens names. Enter adds a new line. Control or Command Enter runs your query.

Query results

Predict the result, then run your query.

Predict the result, then run your query.

Read-only activity · One statement per run · First 200 rows displayed · Checks compare the complete bounded result, not just this preview.

Explore this query freely in the playground ↗

Check the save status above. Account-saved work is available in My Progress. Explanations are for discussion, not automatically graded. No prerequisite locks.