Kaz
Kaz

Reputation: 1466

SQL select distinct column

I've a query which returns the following data

enter image description here

as you can see in the image the colored groups are similar regarding column "A" i want to take the first occurrence of these rows regarding column "A" and discard the rest.

so i can end up with this result.

enter image description here

any solutions?

Thanks :)

Update:

this is the original query results enter image description here

Upvotes: 5

Views: 159

Answers (1)

Vikdor
Vikdor

Reputation: 24134

I would do it as follows:

WITH T(A, B, C, D, RowNum) AS 
(
    SELECT A, B, C, D, ROW_NUMBER() OVER (PARTITION BY A ORDER BY A)
    FROM MyTable
)
SELECT * FROM T
WHERE 
    RowNum = 1

Upvotes: 6

Related Questions