Re: How to force select to return exactly one row

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to force select to return exactly one row
Date: 2010-06-21 23:41:20
Message-ID: m3fx0g2btr.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 Brett Mc Bride 2010-06-21 23:49:13 Re: How to force select to return exactly one row
Previous Message Brett Mc Bride 2010-06-21 23:23:01 Re: How to force select to return exactly one row