Re: SELECT from two tables with different field names?

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: SELECT from two tables with different field names?
Date: 2011-12-13 09:33:58
Message-ID: jc7649$6k4$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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.

Regards
Thomas

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Pandu Poluan 2011-12-13 11:38:08 Re: SELECT from two tables with different field names?
Previous Message Aleksej Trofimov 2011-12-13 09:16:50 Postgresql array parser