| От | Gregory Wood |
|---|---|
| Тема | Re: Two joins on same foreign key |
| Дата | |
| Msg-id | 401ADDFD.7000201@ewebengine.com обсуждение исходный текст |
| Ответ на | Two joins on same foreign key (Anony Mous <a.mous@shaw.ca>) |
| Список | pgsql-general |
> I’m fairly new to this database, and have read much discussion on > sub-queries. I’ve seen that they can be great for some queries, and > downright slow for others. I have a table with two foreign keys > referencing another table, like: > > 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! Just do two joins against the first table: SELECT * FROM table2 JOIN table1 tl ON (teamleader_employee_id=tl.employee_id) JOIN table1 b ON (backup_employee_id=b.employee_id); Greg
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера