Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use same table in JOIN twice?
Message
From
08/05/2009 11:25:33
 
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:
01398637
Views:
122
This message has been marked as the solution to the initial question of the thread.
>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 ;
>   ACCTFILE.ACCT_NAME FROM POHEADER ;
>  JOIN POITEMS ON POITEMS.PK_FLD = POHEADER.PK_FLD ;
>  JOIN ACCTFILE ON POHEADER.ACCT_NUM = ACCTFILE.ACCT_NUM ;
>  JOIN ACCTFILE ON POITEMS.ACCT_NUM = ACCTFILE.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,

It's easy to use a table more than once in a query - simply qualify the table

sample
select Field1, ...
         from Table1 T1 ;
     join Table1 T2 on ( T1.FieldX = T2.FieldX)
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform