SQL OUTER JOIN with NEWID to generate random data for each row

Posted by CL4NCY on Stack Overflow See other posts from Stack Overflow or by CL4NCY
Published on 2010-03-15T14:36:14Z Indexed on 2010/03/15 14:39 UTC
Read the original article Hit count: 176

Filed under:
|

Hi, I want to generate some test data so for each row in a table I want to insert 10 random rows in another, see below:

INSERT INTO CarFeatures (carID, featureID)
SELECT C.ID, F.ID
FROM dbo.Cars AS C
OUTER APPLY (
SELECT TOP 10 ID
FROM dbo.Features
ORDER BY NEWID()
) AS F

Only trouble is this returns the same values for each row. How do I order them randomly?

© Stack Overflow or respective owner

Related posts about sql

Related posts about random