Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use subquery
Message
 
À
14/06/2011 09:21:46
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:
01514285
Message ID:
01514286
Vues:
67
>I am trying to figure out how to use a subquery in the following example:
>
>Table1
>PK_FLD, TASK_NO
>
>Table2
>TASK_NO, FLDA, FLDB
>
>I want the resulting query to have as many records as there are in Table1 adding columns FLDA and FLDB from
>Table2 according to the matching TASK_NO.
>
>My attempt at this query is as following
>
>Select Table1.PK_FLD, Table1.TASK_NO, T2.FLDA, T2.FLDB from Table1 where (select * from Table2 where 
>TASK_NO = Table1.TASK_NO) T2 
>
>
>But I get error of incorrect use of subquery. What am I missing? TIA.

use JOIN instead of subquery.
Select Table1.PK_FLD,;
       Table1.TASK_NO,;
       T2.FLDA,;
       T2.FLDB;
from Table1 ;
INNER JOIN Table2 T2 ON T2.TASK_NO = Table1.TASK_NO;
** You could use LEFT JOIN if you want ALL records from Table1 and only matching records from Table2
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform