Skip site navigation (1) Skip section navigation (2)

Re: SELECT from two tables with different field names?

From: Pandu Poluan <pandu(at)poluan(dot)info>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: SELECT from two tables with different field names?
Date: 2011-12-13 11:38:08
Message-ID: CAA2qdGU=O1+yC-p1ECRTrsXuz5tSOyOfTugh6+fEvaOAzo5j_Q@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Dec 13, 2011 4:34 PM, "Thomas Kellerer" <spam_eater(at)gmx(dot)net> wrote:
>
> Pandu Poluan, 13.12.2011 04:40:
>
>>  > Yes a UNION should do (actually a UNION ALL as it will not try to
remove duplicates which makes the query faster)
>>  >
>>  > select *
>>  > from (
>>  >   select emp_id, fullname
>>  >   from table_one
>>  >
>>  >   union all
>>  >
>>  >   select employee_id,
>>  >          first_name||' '||last_name
>>  >   from table_two
>>  > ) t
>>  > where emp_id = 1
>>  >
>>
>> Thank you! I can see how UNION ALL will speed the query.
>>
>> But, shouldn't I put the WHERE clause in the inner SELECTs?
>
>
> I thought your goal was to just have a single condition. But if you can
push that into the union that would be more efficient.
>

Well, I need a single query not a single condition, but thanks for
confirming :-)

Rgds,

In response to

pgsql-novice by date

Next:From: Merlin MoncureDate: 2011-12-13 14:17:48
Subject: Re: Postgresql array parser
Previous:From: Thomas KellererDate: 2011-12-13 09:33:58
Subject: Re: SELECT from two tables with different field names?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group