When Duplicate Records Appear in Results, Suspect LEFT JOIN / INNER JOIN

Tadashi Shigeoka ·  Tue, July 12, 2022

I’ll introduce a story about how when duplicate records appear in SQL results, you should suspect LEFT JOIN / INNER JOIN.

重複レコード問題 | SQL

Background: Unexpected Duplicate Records in Output

When I executed a query in Google BigQuery, unexpected duplicate records appeared in the results, so I investigated with the following steps:

  1. Check the data stored in each table
  2. Verify if the SQL is incorrect

During this process, I found a problem in the section using LEFT JOIN.

Solution for Duplicate Records Problem

For solutions to the duplicate records problem, please refer to the following articles.

When you encounter duplicate records issues, first suspect the JOIN.

That’s all from the Gemba, where I want to suspect LEFT JOIN / INNER JOIN when duplicate records appear in SQL results.