Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 68854171224F for ; Tue, 6 Mar 2012 17:00:50 -0400 (AST) Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S51V0-0005RR-5T for pgsql-sql@postgresql.org; Tue, 06 Mar 2012 21:00:47 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1S51Um-0008MS-Lm for pgsql-sql@postgresql.org; Tue, 06 Mar 2012 13:00:32 -0800 Date: Tue, 6 Mar 2012 13:00:32 -0800 (PST) From: rverghese To: pgsql-sql@postgresql.org Message-ID: <1331067632664-5542231.post@n5.nabble.com> Subject: map row in one table with random row in another table MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.1 (/) X-Archive-Number: 201203/30 X-Sequence-Number: 36425 Hi, I am trying to map every row in one table with a random row in another. So for e.g. , for each network in 1 table I am trying to map random segments from the other table. I have this sql below, but it always applies the same random segment that it picks to all the rows for the network. I want each row to have a random segment value. I'm just using the generate_series function to generate id's as an e.g. Any suggestions? My Query select id, seg_list from (select generate_series(1,10) as id) as X, (select segment from segments order by random() limit 1 ) as Y I get 1;'cob0002' 2;'cob0002' 3;'cob0002' 4;'cob0002' 5;'cob0002' 6;'cob0002' 7;'cob0002' 8;'cob0002' 9;'cob0002' 10;'cob0002' What I want is 1;'cob0002' 2;'cob0008' 3;'cob0006' 4;'cob0004' 5;'cob0002' 6;'cob0007' 7;'cob0003' 8;'cob0004' 9;'cob0009' 10;'cob0001' I also tried select generate_series(1,10), (select segment from segments order by random() limit 1 ) -- View this message in context: http://postgresql.1045698.n5.nabble.com/map-row-in-one-table-with-random-row-in-another-table-tp5542231p5542231.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.