Reputation: 109
I have some records that looks like this.
I want to pull out as the following.
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
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
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