I know other answers here (and here) say to order by newid(). However if I am selecting top 1 in a subquery - so as to generate a random selection per row in the outer query - using newid() yields the same result each time.
That is:
select *,
(select top 1 [value] from lookupTable where [code] = 'TEST' order by newid())
from myTable
... yields the same lookupTable.value value on each row returned from myTable.
I'm trying to pick a random value from lookupTable. That table has only a few rows. In the real world I want to update myTable set someColumn = ... a random lookupTable.value value such that each row in myTable is set with a random value and not such that a single random value is generated and assigned to all rows.
order by newid(), checksum(myTable.anyColumn, lookupTable.anyColumn). Shame MS doesn't simply allow a keyword phrase likewith(not deterministic). – youcantryreachingme Sep 14 '20 at 00:10