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.
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:
- Check the data stored in each table
- 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.
- sqlのテーブル結合(left join)時の注意点 ー表で解説ー - Qiita
- LEFT JOIN / INNER JOIN を実行すると同じ内容のレコードが複数含まれる : SQL構文 | iPentec
- 【SQL】検索結果の数値が2倍になる(重複)件について - 30代半ばの事務職員がITエンジニアになった話
That’s all from the Gemba, where I want to suspect LEFT JOIN / INNER JOIN when duplicate records appear in SQL results.