Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use same table in JOIN twice?
Message
De
08/05/2009 11:25:33
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01398632
Message ID:
01398637
Vues:
123
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform