Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SELECT SQL Statement
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00506284
Message ID:
00508278
Vues:
17
Dore & Cives

*** previous messges
>Select Table2.DivisionId FROM Table1, Table2
>Where Table2.DivisionName = Table1.DivisionName
>Into Cursor TmpCursor
>
>Would the above work?
Alternatively,
SELECT DivisionID FROM Table2 WHERE ;
DivisionName IN ;
(SELECT DivisionName FROM Table1)

In my opinion, this is preferable because you don't
have to qualify the field names with the table that
they belong to.
*** end previous

The "SELECT...FROM... WHERE... IN (subselect)" is also faster.

The first SQL statement is performing a join between the two tables and is therefore comparing all the join values in the two tables. The second SQL statment is collecting a subset of join values from Table2 and then performing a comparison of Table1's join values against the subset.

However, if there are duplicates of Table1.DivisionName a faster query would be:

SELECT DivisionId ;
FROM Table2 ;
WHERE DivisionName IN ;
(SELECT DISTINCT DivisionName ;
FROM Table1)...

In this query the subquery is collecting unique values of DivisionName, which will speed the query even more.

Regards,
Thom C.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform