RAND()
hanya dijalankan sekali per kueri.
Anda dapat memverifikasi ini dengan melihat kumpulan hasil.
Jika Anda mencoba untuk mendapatkan pesanan acak, Anda harus menggunakan NEWID()
atau CHECKSUM(NEWID())
.
WITH T AS ( -- example using RAND()
SELECT 'Me' Name UNION SELECT 'You' UNION SELECT 'Another'
)
SELECT Name, RAND()
FROM T;
WITH T AS ( -- example using just NEWID()
SELECT 'Me' Name UNION SELECT 'You' UNION SELECT 'Another'
)
SELECT Name, NEWID()
FROM T;
WITH T AS ( -- example getting the CHECKSUM() of NEWID()
SELECT 'Me' Name UNION SELECT 'You' UNION SELECT 'Another'
)
SELECT Name, CHECKSUM(NEWID())
FROM T;