Re: Two Tables That Share Data?

From: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>
To: Michael Wood <esiotrot(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Two Tables That Share Data?
Date: 2012-02-09 16:34:28
Message-ID: CAAQLLO5pY7ASQzZQ-5adeOF60F0Vs8F7=gUaOhTdJeD-B3UqTA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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)

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Bartosz Dmytrak 2012-02-09 21:06:11 Re: Two Tables That Share Data?
Previous Message Michael Wood 2012-02-09 16:28:41 Re: Two Tables That Share Data?