X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id CA7199FA432 for ; Sat, 6 May 2006 05:20:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 94752-10 for ; Sat, 6 May 2006 05:20:00 -0300 (ADT) X-Greylist: delayed 00:06:39.596466 by SQLgrey- Received: from titan.startnet.cz (unknown [82.113.63.73]) by postgresql.org (Postfix) with ESMTP id 66CE89F944D for ; Sat, 6 May 2006 05:19:58 -0300 (ADT) Received: (qmail 12619 invoked from network); 6 May 2006 10:13:16 +0200 Received: from unknown (HELO ?192.168.1.2?) (miroslav.sulc@startnet.cz@10.15.192.25) by titan.local.startnet.cz with ESMTPA; 6 May 2006 10:13:16 +0200 Message-ID: <445C5A94.4020907@startnet.cz> Date: Sat, 06 May 2006 10:13:08 +0200 From: =?ISO-8859-2?Q?Miroslav_=A9ulc?= Organization: StartNet s.r.o. User-Agent: Thunderbird 1.5.0.2 (X11/20060501) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Most efficient way to hard-sort records Content-Type: multipart/mixed; boundary="------------000305060201050907040606" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/63 X-Sequence-Number: 25094 This is a multi-part message in MIME format. --------------000305060201050907040606 Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 8bit Hello, I have a table with cca 100,000 records. I need to hard-sort the records by a key from second table. By hard-sorting I mean storing position of each row in the main table. Here is what my tables look like: main_table: id, name, position key_table: id, main_table_id, key, value Here is how I need to sort the records: SELECT * FROM main_table INNER JOIN key_table ON main_table.id = key_table.main_table_id WHERE key = 'param' ORDER BY value I currently collect all ids from main_table in sorted order and then update the position field for each row in the main_table one-by-one. Is there a better/faster/more efficient solution? Thank you for your suggestions. -- Miroslav Šulc --------------000305060201050907040606 Content-Type: text/x-vcard; charset=utf-8; name="miroslav.sulc.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="miroslav.sulc.vcf" begin:vcard fn;quoted-printable:Miroslav =C5=A0ulc n;quoted-printable:=C5=A0ulc;Miroslav org:StartNet s.r.o. adr;quoted-printable;quoted-printable:;;Schodov=C3=A1 309/10;Praha 5;;150 00;=C4=8Cesk=C3=A1 republika email;internet:miroslav.sulc@startnet.cz tel;cell:+420 603 711 413 x-mozilla-html:TRUE url:http://www.startnet.cz version:2.1 end:vcard --------------000305060201050907040606--