File size: 963 Bytes
e6091f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---
id: "duckdb-check-duplicate-rows"
title: "Check Duplicate Rows"
slug: "duckdb-check-duplicate-rows-query"
description: "Count the number of duplicate rows in a table using DuckDB."
code: |
    -- Count duplicate rows in the 'train' table
    SELECT COUNT(*) - COUNT(DISTINCT columns(*))
    FROM train;
---

# DuckDB Check Duplicate Rows Query

This snippet demonstrates how to count the number of duplicate rows in a DuckDB table using a SQL query.

```sql
-- Count duplicate rows in the 'train' table
SELECT COUNT(*) - COUNT(DISTINCT columns(*))
FROM train;
```

This query works by:
1. Counting all rows using `COUNT(*)`
2. Subtracting the count of distinct rows using `COUNT(DISTINCT *)`
3. The result is the number of duplicate rows

You can replace 'train' with the name of your specific table to check for duplicates in other tables.

Note: This query can be computationally expensive for large tables, as it needs to check all columns for uniqueness.