Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TBwDX-0003sg-7Z for pgsql-sql@postgresql.org; Wed, 12 Sep 2012 23:19:35 +0000 Received: from mail-yw0-f46.google.com ([209.85.213.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TBwDV-0004pB-60 for pgsql-sql@postgresql.org; Wed, 12 Sep 2012 23:19:34 +0000 Received: by yhmm54 with SMTP id m54so564351yhm.19 for ; Wed, 12 Sep 2012 16:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=/DxMR05uTkr+0RXVNPD/aNniWU4sqU4Me52fcFTDA6o=; b=s9amm0a2iignLiXT3invYS0xc42TR9TzFF4JyUjfahTpH3z4o53IipoXXfjfaMBRWG N7KcAZ2RlIk9zJyK1I/g/fSSamGdrUV4r3XZIKug/n5qy4gBkirPl8KU4EydCDTDHxFA CxPyV6VOiApC0WGMJ/faEYsP+TdnOwnVR/yjZlNTSVRzTX1doSh23C7GImyhXxdQfu3u B0ko1O4xlyuy9g9bHtG2/0EOGQ96U+vxjJPo9NWR/nEykasEhrGE8A70g2iYefxfMRS6 ejX7A4Zg/Kt4ZsimokhNVpokcGonJKHyTFhlf5GM+CrLx3rbUxxfOuACsSEZj2lKwK4G oSLQ== Received: by 10.236.173.9 with SMTP id u9mr49734yhl.129.1347491971803; Wed, 12 Sep 2012 16:19:31 -0700 (PDT) Received: from [187.64.171.216] ([187.64.171.216]) by mx.google.com with ESMTPS id e16sm19334966ani.22.2012.09.12.16.19.28 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 12 Sep 2012 16:19:30 -0700 (PDT) Message-ID: <505118A7.9020104@gmail.com> Date: Wed, 12 Sep 2012 20:20:07 -0300 From: Rodrigo Rosenfeld Rosas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.6esrpre) Gecko/20120817 Icedove/10.0.6 MIME-Version: 1.0 To: Gavin Flower CC: pgsql-sql@postgresql.org Subject: Re: ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D References: <50510E0C.8080704@archidevsys.co.nz> In-Reply-To: <50510E0C.8080704@archidevsys.co.nz> Content-Type: multipart/alternative; boundary="------------020906000106020302040509" X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201209/27 X-Sequence-Number: 36829 This is a multi-part message in MIME format. --------------020906000106020302040509 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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. --------------020906000106020302040509 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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.

--------------020906000106020302040509--