Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use same table in JOIN twice?
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01398632
Message ID:
01398640
Views:
49
>>Hi,
>>
>>I have a SQL Select that has the same column/field in parent and child tables. Then there is a parent table for these fields. And I want the resulting query to show a field from the second parent table.
>>
>>Here is an example.
>>
>>POHEADER.DBF has field ACCT_NUM
>>POITEMS.DBF has field ACCT_NUM
>>and table
>>ACCTFILE.DBF that has 2 fields ACCT_NUM C(x), and ACCT_NAME C(x).
>>
>>I want the resulting query to have ACCT_NAME for the ACCT_NUM in both the POHEADER and POITEMS table.
>>
>>Here is the SQL Select that does not work:
>>
>>
>>select POHEADER.ACCT_NUM AS ACC_HEAD, POITEMS.ACCT_NUM AS ACC_ITEM ;
>>   AC1.ACCT_NAME FROM POHEADER ;
>>  JOIN POITEMS ON POITEMS.PK_FLD = POHEADER.PK_FLD ;
>>  JOIN ACCTFILE AC1 ON POHEADER.ACCT_NUM = AC1.ACCT_NUM ;
>>  JOIN ACCTFILE AC2 ON POITEMS.ACCT_NUM = AC2.ACCT_NUM
>>
>>
>>Obviously the above SQL Select gives error as you can't have the same table JOINed twice. Is there a way to overcome this?
>
>Dmitry,
>
>You just need to use an alias for your tables, see inside the slightly changed query.

Thank you, Naomi.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform