---
title: "SQL Query to Remove, get Only Duplicates"
description: "SQL Query examples useful to remove duplicates and to get duplicates rows."
url: https://srinimf.com/2015/12/22/best-db2-sql-queries-to-work-on-duplicate-values/
date: 2015-12-22
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2015/12/sql-queries-handle-duplicates.jpg?fit=1200%2C700&ssl=1
categories: ["SQL"]
tags: ["SQL Query DISTINCT", "SQL Query to get Duplicates", "SQL tips and tricks"]
type: post
lang: en
---

# SQL Query to Remove, get Only Duplicates

There are scenarios where you need to [remove duplicates](https://srinimf.com/2014/09/17/db2-v11-new-technique-duplicate-removal/) and you need to get only duplicates. Below examples ideally good for your project purpose.

## SQL Query: [How to](https://srinimf.com/2010/07/04/excel-sheet-how-to-find-duplicates/) **remove** duplicates:

```
SELECT DISTINCT(Column_name) 
from test_table;
```

The above query selects all distinct values.

- ![](https://i0.wp.com/srinimf.com/wp-content/uploads/2020/04/remove-duplicates.jpg?resize=1200%2C700&ssl=1)Remove Duplicates
- ![](https://i0.wp.com/srinimf.com/wp-content/uploads/2020/04/get-duplicates.jpg?resize=1200%2C700&ssl=1)Get Duplicates

## SQL Query: How to get **only duplicate** values (or) You Can Use This Query to Verify Duplicates Exists

```
SELECT COL1, COL2,COL3,COUNT(*)  
FROM TEST_TABLE
WHERE PAN_ID >=10
GROUP BY COL1, COL2, COL3
HAVING COUNT(*) > 1;
```

Related Posts

- [2 SQL Ideas to Remove Duplicate Rows](https://srinimf.com/2015/01/27/sql-eliminating-duplicates-in-a-table/)DateJanuary 27, 2015
- [DB2 v11 SQL: Remove Duplicates Enhancement](https://srinimf.com/2014/09/17/db2-v11-new-technique-duplicate-removal/)DateSeptember 17, 2014
- [How to Use Group By and Having in SQL Query: Best Example](https://srinimf.com/2023/05/26/how-to-use-sql-having-clause-correctly-in-sql-query/)DateMay 26, 2023

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2015%2F12%2F22%2Fbest-db2-sql-queries-to-work-on-duplicate-values%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2015%2F12%2Fsql-queries-handle-duplicates.jpg%3Ffit%3D1200%252C700%26ssl%3D1&description=SQL%20Query%20to%20Remove%2C%20get%20Only%20Duplicates)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2015/12/22/best-db2-sql-queries-to-work-on-duplicate-values/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2015/12/22/best-db2-sql-queries-to-work-on-duplicate-values/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2015/12/22/best-db2-sql-queries-to-work-on-duplicate-values/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2015/12/22/best-db2-sql-queries-to-work-on-duplicate-values/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20SQL%20Query%20to%20Remove%2C%20get%20Only%20Duplicates&body=https%3A%2F%2Fsrinimf.com%2F2015%2F12%2F22%2Fbest-db2-sql-queries-to-work-on-duplicate-values%2F&share=email)
-

### Like this:

Like Loading…
