From: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
To: Gavin Flower <GavinFlower@archidevsys.co.nz>
Cc: pgsql-sql@postgresql.org
Subject: Re: ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D
Date: Wed, 12 Sep 2012 20:20:07 -0300
Message-ID: <505118A7.9020104@gmail.com> (raw)
In-Reply-To: <50510E0C.8080704@archidevsys.co.nz>
References: <CAGmv+wKCpc9VeyYp6nS9WL1vrtX=3+i87mFVMP4sEpB1LyPGQA@mail.gmail.com>
<50510E0C.8080704@archidevsys.co.nz>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: rr.rosas@gmail.com, GavinFlower@archidevsys.co.nz
Subject: Re: ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D
In-Reply-To: <505118A7.9020104@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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