Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Correlated subquery
Message
 
 
À
17/03/2021 17:29:41
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01679045
Message ID:
01679094
Vues:
44
>Hi Naomi,
>
>Perhaps one last question: does it matter or is it best practice to give aliases to the tables that are used in the subquery - it seems to work either way. Or is it just to be clear and to shorten the table names to short aliases?
>
>I am trying to "think" of what the subquery is actually doing. This runs and gives the same result set but maybe there is a possible future problem:
>
>
>SELECT ;
>   Plaintiffs.Plaintiff_ID, Plaintiff_Files.File_ID ;
>   FROM Plaintiffs  JOIN Plaintiff_Files pf ;
>      ON Plaintiffs.Plaintiff_ID == pf.Plaintiff_ID ;
>    WHERE  pf.Date_Closed < ldCutOffDate AND ;
>        NOT EXISTS ( SELECT 1 FROM Plaintiff_Files f WHERE Date_Closed IS NULL and f.Plaintiff_ID == Plaintiff.Plaintiff_ID  ) ;
>   INTO CURSOR Results
>
>

Yes, this query is also correct - as you can see, there are multiple ways to get the same results. I always use aliases for subqueries and for multiple tables joining for every column as well. This is a good practice and also self-documenting and allows to avoid hard to find bugs in the code.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform