I am trying to add a column in a SQL query to use as an alternative ID. The data has this format:
UserID | Value
---------------
1 | 23
2 | 10
1 | 45
I'd like to create another column that is another number but respects the ID uniqueness. Like so
MaskedID | Value
---------------
9 | 23
8 | 10
9 | 45
I've tried using a subquery which creates a table with a random number, but the random number is not staying the same for the first ID:
Select b.Masked, a.value
from table a
left join
(select distinct(UserID), dbms_random.value(1,100000) as Masked) b on a.UserID=b.UserID
But that results in:
MaskedID | Value
---------------
7 | 23
8 | 10
9 | 45
The # of userIDs may change with time so it's not something that should be predefined. Would a CTE keep the random numbers from being regenerated in the final table?
DISTINCTis not a function. It acts on an entire row.SELECT DISTINCT(UG.USERID), (UG.USERDESC),(UG.EMAIL), (UG.ACL) FROM USERS UGIt will be just as good. Parenthesis act as separator in SQL and thereforeSELECT DISTINCT(UG.USERID),Is same asSELECT DISTINCT UG.USERID," ... SO!!! Potentially OP just separatedDISTINCTandUSERIDusing parenthesis vs space. So, who is getting caught here, OP or you? This is a contest