forum

Home / DeveloperSection / Forums / Join a single row in one table to n random rows in another

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

Samuel Fernandes195706-May-2013
Hi Everyone!


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.

Thanks in advance!

Updated on 06-May-2013

Can you answer this question?


Answer

1 Answers

Liked By