Received: from wolff.to (wolff.to [64.81.147.230]) by postgresql.org (8.11.3/8.11.1) with SMTP id f5DDDcE29734 for ; Wed, 13 Jun 2001 09:13:38 -0400 (EDT) (envelope-from bruno@wolff.to) Received: (qmail 20972 invoked by uid 500); 13 Jun 2001 13:16:56 -0000 Date: Wed, 13 Jun 2001 08:16:56 -0500 From: Bruno Wolff III To: =?iso-8859-1?Q?Mart=EDn_Marqu=E9s?= Cc: David Olbersen , pgsql sql Mailing List , pgsql-general@postgresql.org Subject: Re: [SQL] ORDER BY what? Message-ID: <20010613081656.A20924@wolff.to> Mail-Followup-To: Bruno Wolff III , =?iso-8859-1?Q?Mart=EDn_Marqu=E9s?= , David Olbersen , pgsql sql Mailing List , pgsql-general@postgresql.org References: <01061215532200.04895@bugs> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i In-Reply-To: <01061215532200.04895@bugs>; from martin@bugs.unl.edu.ar on Tue, Jun 12, 2001 at 03:53:22PM +0300 X-Archive-Number: 200106/456 X-Sequence-Number: 10908 On Tue, Jun 12, 2001 at 03:53:22PM +0300, Martín Marqués wrote: > On Mar 12 Jun 2001 02:23, David Olbersen wrote: > > On Mon, 11 Jun 2001, Martín Marqués wrote: > > > My question is: "How can I write an ORDER BY statment so that it's > > > ordered by the amount of matches it gets?" > > > > Your question is a bit unclear, what is "it"? > > Specifically, what are the "it's" that are to be ordered, and which "it" > > gets matches? > > OK, let me give an example: > > select * from tab1 where col1 like '%word%' or col2 like '%word%' and col3 > like '%word%' > > and I want to order by the amopunt of matches that a matching register has. > Something like, if it matches all the ORs, then it should go first, and if it > matches only one of the ORs it should go last. > Or maybe even have several words trying to match one of the columns. You could do this by computing a value based on the number of parts that matched and order by it.