Skip site navigation (1) Skip section navigation (2)

Re: order of results

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Gregor Rot <zara4tustra(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: order of results
Date: 2004-03-26 21:53:03
Message-ID: 20040326215303.GC21119@wolff.to (view raw or flat)
Thread:
Lists: pgsql-sql
On Thu, Mar 25, 2004 at 14:23:00 +0100,
  Gregor Rot <zara4tustra(at)yahoo(dot)com> 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.

In response to

Responses

pgsql-sql by date

Next:From: Tom LaneDate: 2004-03-26 23:03:13
Subject: Re: date_part stored procs
Previous:From: Tom LaneDate: 2004-03-26 21:43:11
Subject: Re: Invalid Unicode Character Sequence found

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group