X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 27A4AD1B974 for ; Fri, 26 Mar 2004 21:49:50 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 83631-07 for ; Fri, 26 Mar 2004 17:49:56 -0400 (AST) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 0173CD1B88A for ; Fri, 26 Mar 2004 17:49:48 -0400 (AST) Received: (qmail 21347 invoked by uid 500); 26 Mar 2004 21:53:03 -0000 Date: Fri, 26 Mar 2004 15:53:03 -0600 From: Bruno Wolff III To: Gregor Rot Cc: pgsql-sql@postgresql.org Subject: Re: order of results Message-ID: <20040326215303.GC21119@wolff.to> Mail-Followup-To: Gregor Rot , pgsql-sql@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/256 X-Sequence-Number: 17355 On Thu, Mar 25, 2004 at 14:23:00 +0100, Gregor Rot wrote: > Hi, > > i have a table called "people" (name:varchar, lastname:varchar). > > i do a select on it: > > select * from people where name like '%n1%' or lastname like '%l1%'. > > i would like the results in this order: > > first the results that satisfy only the (name like '%n1%') condition, > then the ones that satisfy only the (lastname like '%l1%') condition and > last the results that satisfy both conditions. > > Is this possible in only one SQL? > (note that the search conditions n1 and l1 differ from search to search. Yes. You can order by true/false results from conditions to get the results in the desired order.