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

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 (view raw or flat)
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

pgsql-novice by date

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

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