Join a single row in one table to n random rows in another
- by Einar Egilsson
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.