pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
order of results
4+ messages / 2 participants
[nested] [flat]

* order of results
@ 2004-03-25 13:23 Gregor Rot <zara4tustra@yahoo.com>
  2004-03-26 21:53 ` Re: order of results Bruno Wolff III <bruno@wolff.to>
  0 siblings, 1 reply; 4+ messages in thread

From: Gregor Rot @ 2004-03-25 13:23 UTC (permalink / raw)
  To: pgsql-sql

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.

TNX,
Gregor



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: order of results
  2004-03-25 13:23 order of results Gregor Rot <zara4tustra@yahoo.com>
@ 2004-03-26 21:53 ` Bruno Wolff III <bruno@wolff.to>
  2004-04-03 15:08   ` Re: order of results Gregor Rot <zara4tustra@yahoo.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Bruno Wolff III @ 2004-03-26 21:53 UTC (permalink / raw)
  To: Gregor Rot <zara4tustra@yahoo.com>; +Cc: pgsql-sql

On Thu, Mar 25, 2004 at 14:23:00 +0100,
  Gregor Rot <zara4tustra@yahoo.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.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: order of results
  2004-03-25 13:23 order of results Gregor Rot <zara4tustra@yahoo.com>
  2004-03-26 21:53 ` Re: order of results Bruno Wolff III <bruno@wolff.to>
@ 2004-04-03 15:08   ` Gregor Rot <zara4tustra@yahoo.com>
  2004-04-07 05:33     ` Re: order of results Bruno Wolff III <bruno@wolff.to>
  0 siblings, 1 reply; 4+ messages in thread

From: Gregor Rot @ 2004-04-03 15:08 UTC (permalink / raw)
  To: pgsql-sql

Bruno Wolff III wrote:
> On Thu, Mar 25, 2004 at 14:23:00 +0100,
>   Gregor Rot <zara4tustra@yahoo.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.

Thank you - sorry, but how do you do that?

Tnx,
Gregor



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: order of results
  2004-03-25 13:23 order of results Gregor Rot <zara4tustra@yahoo.com>
  2004-03-26 21:53 ` Re: order of results Bruno Wolff III <bruno@wolff.to>
  2004-04-03 15:08   ` Re: order of results Gregor Rot <zara4tustra@yahoo.com>
@ 2004-04-07 05:33     ` Bruno Wolff III <bruno@wolff.to>
  0 siblings, 0 replies; 4+ messages in thread

From: Bruno Wolff III @ 2004-04-07 05:33 UTC (permalink / raw)
  To: Gregor Rot <zara4tustra@yahoo.com>; +Cc: pgsql-sql

On Sat, Apr 03, 2004 at 17:08:34 +0200,
  Gregor Rot <zara4tustra@yahoo.com> wrote:
> Bruno Wolff III wrote:
> >On Thu, Mar 25, 2004 at 14:23:00 +0100,
> >  Gregor Rot <zara4tustra@yahoo.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.
> 
> Thank you - sorry, but how do you do that?

Here is a simple example that illustrates what you can do:
bruno=> select col from test order by col like 'bb%', col;
 col
-----
 aaa
 aac
 ccc
 ccd
 bba
 bbb
 bbc
(7 rows)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2004-04-07 05:33 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-03-25 13:23 order of results Gregor Rot <zara4tustra@yahoo.com>
2004-03-26 21:53 ` Bruno Wolff III <bruno@wolff.to>
2004-04-03 15:08   ` Gregor Rot <zara4tustra@yahoo.com>
2004-04-07 05:33     ` Bruno Wolff III <bruno@wolff.to>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox