Re: two foreign keys
От | Josh Berkus |
---|---|
Тема | Re: two foreign keys |
Дата | |
Msg-id | web-695980@davinci.ethosmedia.com обсуждение исходный текст |
Ответ на | two foreign keys (Brian <Brrrian@Excite.com>) |
Ответы |
Re: two foreign keys
|
Список | pgsql-novice |
Brian, > I have a table that has two foreign keys to the same table. > > - operator_id_start > - operator_id_stop > > Both point to the operator table. > > When displaying the row from the table how do I join so that I can > have both Operator table details available? Aha! I love the classic novice questions. So much easier than "I can't get Perl::SSElay to connect with Pgsql>" The bit of SQL knowledge you're missing is called "table aliasing." This is where you give a table a different name in the query than its real name. Aliasing allows you to refer to the same table more than once in a query. So, to answer your question, making up quite a bit of detail about your tables that I don't have: SELECT session_id, session_name, op_start.operator_name, op_end.operator_name FROM sessions JOIN operators op_start ON sessions.operator_start_id = op_start.operator_id JOIN operators op_end ON sessions.operator_end_id = op_start.operator_id; Got it? Now go buy yourself a copy of "SQL Queries for Mere Mortals." -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco
В списке pgsql-novice по дате отправления: