Re: ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D

From: Rodrigo Rosenfeld Rosas <rr(dot)rosas(at)gmail(dot)com>
To: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D
Date: 2012-09-12 23:20:07
Message-ID: 505118A7.9020104@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Em 12-09-2012 19:34, Gavin Flower escreveu:
> On 13/09/12 09:44, Rodrigo Rosenfeld Rosas wrote:
>> This is my first message in this list :)
>>
>> I need to be able to sort a query by column A, then B or C (which one
>> is smaller, both are of the same type and table but on different left
>> joins) and then by D.
>>
>> How can I do that?
>>
>> Thanks in advance,
>> Rodrigo.
>>
>>
> ...
> SELECT
> *
> FROM
> tabc t
> ORDER BY
> t.a,
> LEAST(t.b, t.c),
> t.d
> ...

Thank you Gavin, I was looking for this LEAST function for a long time.
I have tried MIN but it didn't work with strings.

I guess this will allow me to do what I want. Thank you so much!

Best,
Rodrigo.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Wolfe Whalen 2012-09-12 23:53:10 generate_series() with TSTZRANGE
Previous Message Rodrigo Rosenfeld Rosas 2012-09-12 23:18:42 Re: ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D