Re: How to force select to return exactly one row - Mailing list pgsql-general

From Brett Mc Bride
Subject Re: How to force select to return exactly one row
Date
Msg-id 1451A17266557D4C9733B93ACC5DA5C1132D4F6BC5@garnet-1.du.deakin.edu.au
Whole thread Raw
In response to Re: How to force select to return exactly one row  (Tim Landscheidt <tim@tim-landscheidt.de>)
List pgsql-general
My understanding of UNION ALL is that it won't sort the rows...?

-----Original Message-----
From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Tim Landscheidt
Sent: Tuesday, 22 June 2010 9:41 AM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] How to force select to return exactly one row

Brett Mc Bride <brett.mcbride@deakin.edu.au> wrote:

> How about:
> SELECT * from (
> SELECT somecolumns
>  FROM ko
> LEFT JOIN t1 ON t1.primarykey= ko.t1foreignkwey
> ...
> LEFT JOIN tn ON tn.primarykey= ko.tnforeignkwey
> WHERE ko.primarykey='someprimarykeyvalue'
> UNION ALL
> SELECT default_value
> )
> LIMIT 1;
> [...]

... with a proper "ORDER BY" clause.

Tim


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: Tim Landscheidt
Date:
Subject: Re: How to force select to return exactly one row
Next
From: Tim Landscheidt
Date:
Subject: Re: How to force select to return exactly one row