Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Find Duplicate Rows in SQL (and Decide What Counts as One)

By Michael Nocito , data analyst · Published August 7, 2026 By the end of this page you can check any table for duplicate rows, list every copy, and mark which one to keep, all with queries you understand. You will also know the step that comes before any query: deciding what "duplicate" means for this table, because two rows can match on everything or on one column, and those are different…

Finding duplicate rows in SQL can be a crucial task for data analysis and cleaning. To begin, you must first decide what constitutes a duplicate for the specific table you are working with. Two rows may match on all columns or just on one column, leading to different problems and solutions. The first step is to compare the total row count with the distinct key count using the command COUNT(*) against COUNT(DISTINCT key). If these two numbers differ, it indicates the presence of duplicates in the table.

The general approach to finding duplicates involves grouping rows by the columns that define a duplicate, keeping groups where the COUNT(*) is above one, and marking the extras with ROW_NUMBER instead of deleting them. This process can be visualized in three stages.

Stage one presents a column of eight row boxes, with three rows sharing a small square marker and two rows sharing a different marker, signifying that they have the same key value.

Stage two shows these rows collapsed into five buckets. One bucket contains the three matching rows, another holds the two matching rows, and the remaining three buckets hold a single row each. The two buckets containing more than one row are outlined in a warm warning color and labeled with their counts, three and two.

Finally, Stage three displays only the two flagged buckets, which are then passed through to the final result. This visualization demonstrates that grouping rows by their key makes every duplicate visible as a bucket with a count above one, while unique rows form buckets of one and are removed.

To solidify your understanding, you can use a real example. For instance, a 14-row customers table with three seeded duplicates can be examined using SQLite. Every number in this guide comes from this table, and every query was run against it before its output was pasted here. The goal is for you to confirm every result yourself, as the table is small enough to check by eye. If GROUP BY and HAVING are new concepts to you, it is recommended to read about them first before proceeding.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

pandas GroupBy: How to Summarize a DataFrame Without Losing Track of Your Rows

By Michael Nocito , data analyst · Published August 7, 2026 By the end of this page you can take a DataFrame, summarize it by any column or combination of columns, get several statistics at once with…

  • Groupby operation splits DataFrame into mini-tables based on unique values in grouping columns
  • Basic usage: df.groupby(region)[amount].mean() computes mean of 'amount' column for each region
  • Multiple statistics simultaneously using agg and named aggregation for cleaner output

Month-over-Month Growth in SQL: LAG, the Growth Formula, and the Traps

By Michael Nocito , data analyst · Published August 7, 2026 By the end of this page you can write a month-over-month growth query and trust its answer.

  • Month-over-month growth calculated using LAG function
  • LAG function fetches previous month's revenue for comparison
  • Three common traps can lead to incorrect growth calculations

NULL in SQL: Why = NULL Finds Nothing and What to Write Instead

By Michael Nocito , data analyst · Published August 7, 2026 By the end of this page you can predict what any query does when it meets a missing value, which is the skill that separates "my query…

  • NULL represents unknown or missing values in SQL
  • Comparing with = NULL always returns unknown and excludes rows
  • IS NULL operator checks specifically for NULL values

Which SQL Database Should You Install?

By Michael Nocito , data analyst · Published August 7, 2026 If you want to write SQL against your own data today, install a file-based engine: SQLite if you are learning, DuckDB if your data is…

  • File-based databases like SQLite or DuckDB recommended for single-user or small projects
  • Server databases such as PostgreSQL, MySQL, or SQL Server needed for multiple users
  • Choose based on whether simultaneous access to data is required

More from Friday 21 August →