Join a single row in one table to n random rows in another

Posted by Einar Egilsson on Stack Overflow See other posts from Stack Overflow or by Einar Egilsson
Published on 2010-06-16T08:35:03Z Indexed on 2010/06/16 8:52 UTC
Read the original article Hit count: 284

Filed under:
|
|
|

Is it possible to make a join in SQL server that joins each row from table A to n random rows in another? For example, say I have a Customer table, a Product table and an Order table. I want to join each customer to 5 random products and insert these rows into the order table. (And each customer should be joined to 5 random rows of his own, I don't want all customers joining to the same 5 rows).

Is this possible? I'm using SQL Server 2005 and it's fine if the solution is specific to that.

This is a weird requirement but I'm basically making a small data generator to generate some random data.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server