Module 5 · Data that arrives dirty

Duplicates: finding them, and deciding which row survives

In this lesson

  • 8 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 6 of 12 in this chapter

This chapter’s goalLoad an exported CSV with mixed encodings, ambiguous dates and duplicate rows into a typed, deduplicated table by re-runnable query with every dropped row counted, decide and document what each missing value means, and produce a feature table for a model in which no column knows anything that happened after its row’s timestamp.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available
Two kinds of duplicate, and what each tool does with themSELECT DISTINCTrow_number = 1Identical rowsCollapsedreal repeats die tooOne keptby a rule you can stateSame key onlyBoth survivethe retry staysOne keptnewest, ties by idDISTINCT keeps any row that differs in any column, so a retry that differs by one timestamp surviveswhile two genuinely separate payments that happen to match are merged. It is wrong in both directionsat once. A ranking with a stated ordering is a decision you can explain.
DISTINCT keeps any row that differs in any column, so a retry that differs by one timestamp survives while two genuinely separate payments that happen to match are merged. It is wrong in both directions at once. A ranking with a stated ordering is a decision you can explain.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

Three kinds of duplicate

The earlier cleaning lesson made the point that whether two rows are “the same” is a business question. This lesson is about the mechanics once the question is answered, and there are three different mechanics because there are three different kinds of duplicate.

Exact duplicates are rows identical in every column. They come from a file pasted twice or a job that ran twice. Key duplicates share the identifying columns and differ elsewhere: the same payment reference with two timestamps, because a retry recorded a second row. Near duplicates share nothing exactly and are still the same thing: ada@example.com and Ada@Example.com, or +91 98765 43210 and 9876543210.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Building Apps with AI exam.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘Duplicates: finding them, and deciding which row survives’, in Data, SQL and Getting to the Answer. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/data-and-sql/duplicates-and-which-to-keep (Accessed: 29 November 2026).