Beginner

699. JOIN with CONCAT

Use concatenated values as a JOIN key when the business identifier is stored across multiple columns.

📘 Lesson 699 of 728 ⏱ 14 min 🎯 Advanced

CONCAT combines multiple values into one string that can be compared with a corresponding combined value.

Legacy systems sometimes store a business identifier in separate fields while another system stores it as one value.

Match records using BranchCode and AccountNumber combined into a single reference.

SQL
SELECT
    a.AccountNumber,
    r.ReferenceValue
FROM Accounts a
INNER JOIN ExternalReferences r
    ON CONCAT(a.BranchCode, '-', a.AccountNumber)
     = r.ReferenceValue;

Used in legacy integration, migration, reconciliation, and cross-system matching.

  • CONCAT combines values into a string.
  • Separators can prevent ambiguous combinations.
  • Data type conversion may be required.
  • Expression-based JOINs can affect performance.
  • A standardized key is preferable when possible.
Why use CONCAT in a JOIN?

It can match a combined business key against a value stored as one string.

Why use a separator in CONCAT?

A separator can reduce ambiguity between combinations of values.

Have you finished this lesson?

Introduction to SQL – All Lessons