Re: How to force select to return exactly one row

From: Brett Mc Bride <brett(dot)mcbride(at)deakin(dot)edu(dot)au>
To: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to force select to return exactly one row
Date: 2010-06-21 23:49:13
Message-ID: 1451A17266557D4C9733B93ACC5DA5C1132D4F6BC5@garnet-1.du.deakin.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

My understanding of UNION ALL is that it won't sort the rows...?

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

Brett Mc Bride <brett(dot)mcbride(at)deakin(dot)edu(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Landscheidt 2010-06-22 00:20:35 Re: How to force select to return exactly one row
Previous Message Tim Landscheidt 2010-06-21 23:41:20 Re: How to force select to return exactly one row