Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Nondeterministic Functions in MySQL (i.e. Rand) Can Surprise You.
SELECT * FROM SomeTable WHERE ID = CAST(Rand() * 1000 as int)
In addition this query: SELECT TOP(100) rand() AS RandData from SomeTable
Returns: 0.940284064056996 0.940284064056996 0.940284064056996 . . . .
A old trick to actually get random data on SQL Server that I think has been replaced with newer functionality is:
SELECT ABS(CHECKSUM(NEWID())) FROM SomeTable
However if we move the NEWID.... stuff into the WHERE clause we end up switching to an index seek so back to being evaluated once.
There are no comments on this comment yet.
SELECT * FROM SomeTable WHERE ID = CAST(Rand() * 1000 as int)
In addition this query: SELECT TOP(100) rand() AS RandData from SomeTable
Returns: 0.940284064056996 0.940284064056996 0.940284064056996 . . . .
A old trick to actually get random data on SQL Server that I think has been replaced with newer functionality is:
SELECT ABS(CHECKSUM(NEWID())) FROM SomeTable
However if we move the NEWID.... stuff into the WHERE clause we end up switching to an index seek so back to being evaluated once.