Re: Two Tables That Share Data?

Поиск
Список
Период
Сортировка
От Bartosz Dmytrak
Тема Re: Two Tables That Share Data?
Дата
Msg-id CAD8_Ucb2f9B7Xumg71ksA2z7g8KmGjq-hS1aB-9vDy5DXqgYRw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Two Tables That Share Data?  (Carlos Mennens <carlos.mennens@gmail.com>)
Список 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.mennens@gmail.com>
On Thu, Feb 9, 2012 at 11:28 AM, Michael Wood <esiotrot@gmail.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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

В списке pgsql-novice по дате отправления:

Предыдущее
От: Carlos Mennens
Дата:
Сообщение: Re: Two Tables That Share Data?
Следующее
От: Falk Grossmann
Дата:
Сообщение: timestamp in log table after update in another table