Lamin
Lamin

Reputation: 109

How to pull the duplicate record in SQL

I have some records that looks like this.

enter image description here

I want to pull out as the following.

Second Pic

Is this possible?

I can only pull out the duplicate values but can't get that I want.

SELECT [COLUMN A] , COUNT([COLUMN A]) FROM [MYTABLE] GROUP BY [COLUMN A] HAVING COUNT([COLUMN A]) >1 ORDER BY [COLUMN A]

Anyone please help me. Thanks.

Upvotes: 0

Views: 217

Answers (2)

Joseph B
Joseph B

Reputation: 5669

You can use the following query to get the desired result:

SELECT 
    ColumnA
    , MAX(ColumnB) ColumnB
    , MIN(ColumnC) ColumnC
    , MAX(ColumnC) ColumnD
FROM MYTABLE
GROUP BY ColumnA
ORDER BY ColumnA;

Upvotes: 1

fsalazar_sch
fsalazar_sch

Reputation: 455

Try in the 'Count()' sentence add the id or * i.e.:

SELECT [COLUMN A] , COUNT(*) FROM [MYTABLE] GROUP BY [COLUMN A] HAVING COUNT(*) >1 ORDER BY [COLUMN A]

or

SELECT [COLUMN A] , COUNT(´id_col_A´) FROM [MYTABLE] GROUP BY [COLUMN A] HAVING COUNT(´id_col_A´) >1 ORDER BY [COLUMN A]

Upvotes: 0

Related Questions