Saltar al contenido

Lección 9 · Blending and Joining

The Join Tool

Combine two tables with the Alteryx Join tool, read its L, J and R outputs, build left and full outer joins and avoid row explosions from duplicate keys.

Blending means combining data from different sources. The most common step is a join: you match rows from two inputs using a shared field such as a customer ID. In Designer this is the Join tool.

If you know SQL joins, you will recognize the ideas. The difference is that one Join tool gives you three separate outputs.

Configuring a join

Connect one stream to the L (left) input and another to the R (right) input. In the Configuration window, choose how to match:

  • Join by specific fields: pick one or more key fields from each side. This is the usual choice.
  • Join by record position: row 1 matches row 1, row 2 matches row 2. Use it only when both streams are guaranteed to have the same order.

The tool also contains a field list, like the Select tool, to remove or rename columns in the joined result. When both sides have a field with the same name, Designer renames the right-side one, often with a Right_ prefix. Remove or rename duplicates right here to keep your data clean.

The three outputs

Anchor Contains
J Matched rows, with fields from both sides
L Left rows that found no match
R Right rows that found no match

To build the common SQL join types, you combine outputs with a Union tool:

SQL join Alteryx
Inner J only
Left outer J + L into Union
Right outer J + R into Union
Full outer J + L + R into Union
flowchart LR
  A["Left table"] --> J["Join"]
  B["Right table"] --> J
  J -->|J| U["Union"]
  J -->|L| U
  U --> O["Left outer result"]

A left outer join: matched rows plus unmatched left rows.

The Designer help suggests connecting the J output to the Union first, so that it sets the field layout of the combined result.

Seeing it with SQL

SQL Stand-in: J, L and R as SQL queries

Press Run (or Ctrl + Enter) to see the result here.

The R output found order 20 for customer 9, who does not exist in the customer table. In real work, that is a data quality finding you should report.

Row multiplication

If a key appears more than once on both sides, every left row matches every right row with that key. Three rows on the left and four on the right become twelve rows. Totals then look much larger than they should.

Python Stand-in: count keys before you join

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

To prevent this, check that the lookup side has one row per key. Use a Unique tool or a Summarize tool with Group By and Count, then filter for counts above one.

Key quality

A join compares values as they are. Before you join:

  • Use the same data type on both sides. A number key and a text key do not match well.
  • Trim spaces and standardize case. Treat matching as exact unless your tests show otherwise.
  • Decide what to do with null keys. Filter them out before the join, or test how your version matches them. Do not rely on your SQL habits here.

Reconcile after every join

A reliable habit is to check that the numbers add up:

TEXT
matched left rows (distinct) + L output rows = left input rows

For a one-to-one or many-to-one join, J row count plus L row count equals the left input count. If it is larger, you have duplicate keys on the right.

Many-to-one and one-to-many

Before you join, say which relationship you expect:

Relationship Example Expected J rows
One-to-one Employee and employee profile At most one per left row
Many-to-one Orders and customers At most one per order
One-to-many Customers and orders Can exceed the customer count
Many-to-many Orders and a list with repeated promotions Can grow very large

An unexpected many-to-many is often a sign that a key is incomplete. Perhaps you need both product_id and valid_month, not only the product. You can match on several fields at once, so add the missing part of the key instead of removing duplicates afterward. Removing them afterward keeps an arbitrary row, which hides the real problem.

A habit for new sources

The first time you join two sources, inspect all three outputs and spend a few minutes reading the unmatched rows. Patterns jump out: a prefix on one side only, old codes that were retired or a whole region missing. Fix the cause and run the join again before you build anything on top of it.

Practice task

Make a customer table with five rows and an order table with eight. Include a customer without orders, an order for an unknown customer, a key with a trailing space and a customer who appears twice by mistake.

Predict the row count of the L, J and R outputs, then run the join or write it in the SQL stand-in. Explain every difference from your prediction. Next, fix the key with a trim, remove the mistaken duplicate according to a rule that you state, and join again. Finally, build the left outer result with a Union and confirm that each customer appears at least once.

Common mistakes

Forgetting the L and R outputs hides unmatched records. Send them to a Browse tool or an exception file, and review them.

  • Joining on a name instead of an ID. Names repeat and vary.
  • Using record position when row order is not guaranteed.
  • Keeping two nearly identical columns and using the wrong one later.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which outputs do you union to create a left outer join?

    Matched rows plus unmatched left rows make a left outer join.
  2. 2. A key appears 2 times on the left and 5 times on the right. How many rows appear in J for it?

    Each left row matches each right row: 2 times 5.
  3. 3. What should you do with the R output when orders reference unknown customers?

    Unmatched records often reveal data quality problems.
  4. 4. When is join by record position safe?

    Position matching depends entirely on order.

Summary

  • Join outputs are J (matched), L (left only) and R (right only).
  • Union J with L or R to build outer joins.
  • Duplicate keys on both sides multiply rows.
  • Clean key types and values, and reconcile counts after each join.

Next: Union, Join Multiple and Append Fields

Tu progreso se guarda en este navegador. No necesitas una cuenta.