Re: Two joins on same foreign key

Поиск
Список
Период
Сортировка
От Michael Glaesemann
Тема Re: Two joins on same foreign key
Дата
Msg-id 937DFBB4-53B5-11D8-AB38-000A95C88220@myrealbox.com
обсуждение исходный текст
Ответ на Two joins on same foreign key  (Anony Mous <a.mous@shaw.ca>)
Ответы Re: Two joins on same foreign key  (Anony Mous <a.mous@shaw.ca>)
Список pgsql-general
On Jan 31, 2004, at 7:03 AM, Anony Mous wrote:
> Table #1
> employee_id (pk)
> employee_name 
>
> Table #2
> teamleader_employee_id
> backup_employee_id
>
>  both fields in table 2 need to do a lookup in table 1 to get the name
> of the actual employee.  Do I need to use nested queries to accomplish
> this?  Any help is greatly appreciated!

I think you could handle this by calling table1 twice, but with
different aliases, like so

SELECT leader.employee_name, backup.employee_name
FROM table1 leader, table1 backup, table2 t2
WHERE
    leader.employee_id = t2.teamleader_employee_id AND
    backup.employee_id = t2.backup_employee_id

Does that work for you?

Michael Glaesemann
grzm myrealbox com


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: failed index creation: ERROR: index_formtuple
Следующее
От: Anony Mous
Дата:
Сообщение: Re: Two joins on same foreign key