I have two tables and I want update the column GebruikerID
from table Topic
with the ID of the table Gebruiker
with random values.
You must also know the follow things:
Topic.GebruikerID
references toGebruiker.ID
.- Not every ID is used in both tables.
- The random number that must be generated exist in the table
Gebruiker
(columnID
) and must be updated into the tableTopic
(columnGebruikerID
). - I use SQL server in an express edition.
Here are some images.
Best Answer
You can assign two
ROW_NUMBER
s based on a random sort and join on them:See fiddle
EDIT:
You can use the result of this SELECT to update the
Topic
table:fiddle