Re: Two Tables That Share Data?

From: Bartosz Dmytrak <bdmytrak(at)eranet(dot)pl>
To: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>
Cc: Michael Wood <esiotrot(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Two Tables That Share Data?
Date: 2012-02-09 21:06:11
Message-ID: CAD8_Ucb2f9B7Xumg71ksA2z7g8KmGjq-hS1aB-9vDy5DXqgYRw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,
this is different (old) SQL dialect, where WHERE condition is similar to
INNER JOIN.
There is nothing magic in translation. In Your example employees.manager =
managers.id act the same role as Michael's INNER JOIN managers AS m ON
e.manager = m.id , rest of Your WHERE is simple condition to find employee
'Carlos' and related manager - relation is because previous WHERE condition
exists.
Please notice, that displayed columns depend on SELECT statement, I mean
SELECT and list of columns You want to display.

Regards,
Bartek

2012/2/9 Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>

> On Thu, Feb 9, 2012 at 11:28 AM, Michael Wood <esiotrot(at)gmail(dot)com> wrote:
> > Try something like this:
> >
> > SELECT e.fname AS emp_fname, e.lname AS emp_lname, m.name AS manager
> > FROM employees AS e
> > INNER JOIN managers AS m ON e.manager = m.id
> > WHERE e.salary = 12345.67;
>
> I'm going to try this now but while I was working on this in pgAdmin3
> query builder tool, I got the results I wanted which was to just query
> my employee table and translate the employees.manager field from
> INTEGER to their actual name referenced in 'managers.name' as show
> below:
>
> psql (9.1.2)
> SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
> Type "help" for help.
>
> zoo=# SELECT
> employees.id,
> employees.fname,
> employees.lname,
> managers.name AS manager
> FROM
> employees,
> managers
> WHERE
> employees.manager = managers.id AND employees.fname = 'Carlos';
> id | fname | lname | manager
> ----+--------+---------+---------------
> 1 | Carlos | Mennens | Phill Collins
> (1 row)
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Falk Grossmann 2012-02-10 09:19:48 timestamp in log table after update in another table
Previous Message Carlos Mennens 2012-02-09 16:34:28 Re: Two Tables That Share Data?