teh_sql
teh_sql

Reputation: 1

SQL create row_number from multiple string columns

I have in my table 3 string column and I want to create unique column with a row_nubmer. I have tried something like this but didn't get unique values:

ROW_NUMBER() OVER(PARTITION BY ([Marker1] + [Marker2] + [Marker3])
     ORDER BY ([Marker1] + [Marker2] + [Marker3])  DESC) ROWNUMBER

Upvotes: 0

Views: 128

Answers (1)

id'7238
id'7238

Reputation: 2593

Use the DENSE RANK function:

DENSE_RANK() OVER (ORDER BY [Marker1], [Marker2], [Marker3]) AS ROWNUMBER

Note that you do not need to concatenate strings to identify unique values. This can lead to false positives.

A   B   A+B
-----------
XX  X   XXX
X   XX  XXX

Upvotes: 1

Related Questions