>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