> 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,
JOIN operators op_start ON sessions.operator_start_id =
JOIN operators op_end ON sessions.operator_end_id =
Got it? Now go buy yourself a copy of "SQL Queries for Mere Mortals."
______AGLIO DATABASE SOLUTIONS___________________________
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
In response to
pgsql-novice by date
|Next:||From: Tom Lane||Date: 2002-02-16 23:26:00|
|Subject: Re: two foreign keys |
|Previous:||From: Patrick Hatcher||Date: 2002-02-16 21:58:33|
|Subject: Re: Updated to 7.2 now can't createlang..|