Re: 3 SELECTs rolled into 1 ?

From: Tarlika Elisabeth Schmitz <postgresql(at)numerixtechnology(dot)de>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: 3 SELECTs rolled into 1 ?
Date: 2008-06-04 12:14:58
Message-ID: 20080604131458.03c90540@dick.coachhouse
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 4 Jun 2008 09:55:46 +0200
"A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> wrote:

> am Wed, dem 04.06.2008, um 8:41:29 +0100 mailte Tarlika Elisabeth
> Schmitz folgendes:
> > I have 3 similar SELECTs. I am wondering whether they could be
> > rolled into one?
> >
> >
> > SELECT
> > item.id,
> > department.id || section.id || category.id as x
> > FROM item
> > LEFT JOIN product ON ...
> > LEFT JOIN department ON ...
> > LEFT JOIN section ON ...
> > LEFT JOIN category ON ...
> >
> > ...
> >
> > SELECT
> > item.id,
> > department.id as x
> > FROM item
> > LEFT JOIN product ON ...
> > LEFT JOIN department ON ...
>
>
> If i understand you correctly: use UNION, like
>
> select foo1 as foo, bar1 as bar from table1 UNION ALL select foo2,
> bar2 from table2;
>
> The result table contains 2 columns foo and bar and all rows from both
> selects.

Many thanks!
Yes, this produces the desired result.

It is more or less just a concatenation of virtually identical SELECTs
with the same long WHERE clause. I had hoped to be able to express it
with a single SELECT. ;-)

--

Best Regards,
Tarlika Elisabeth Schmitz

A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad?

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message sathiya moorthy 2008-06-05 05:31:35 Re: Problems with a Query between 7.3 and 8.2
Previous Message Holm Tiffe 2008-06-04 12:05:42 Re: Problems with a Query between 7.3 and 8.2