Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 0E0239FB71C for ; Wed, 14 Feb 2007 02:42:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 39278-06 for ; Wed, 14 Feb 2007 02:42:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from proton.planetargon.com (proton.planetargon.com [198.145.37.35]) by postgresql.org (Postfix) with ESMTP id B95B99FB316 for ; Wed, 14 Feb 2007 02:42:08 -0400 (AST) Received: from [172.16.1.106] (unknown [61.197.227.146]) by proton.planetargon.com (Postfix) with ESMTP id 0493C866008; Tue, 13 Feb 2007 22:42:04 -0800 (PST) In-Reply-To: <445C5A94.4020907@startnet.cz> References: <445C5A94.4020907@startnet.cz> Mime-Version: 1.0 (Apple Message framework v749.3) Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes; format=flowed Message-Id: Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable From: Michael Glaesemann Subject: Re: Most efficient way to hard-sort records Date: Wed, 10 May 2006 12:24:56 +0900 To: =?WINDOWS-1252?Q?Miroslav_=8Aulc?= X-Mailer: Apple Mail (2.752.2) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.021 tagged_above=0 required=5 tests=BAYES_50, DATE_IN_PAST_96_XX X-Spam-Level: ** X-Archive-Number: 200702/155 X-Sequence-Number: 27489 On May 6, 2006, at 17:13 , Miroslav =8Aulc wrote: > I have a table with cca 100,000 records. I need to hard-sort the =20 > 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 =3D key_table.main_table_id > WHERE key =3D 'param' > ORDER BY value I don't know about faster or more efficient, but here's an =20 alternative that I haven't seen yet: Michael Glaesemann grzm seespotcode net