Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
AS Clause
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00409807
Message ID:
00409968
Vues:
28
Tom and everyone,

The Having clause is NOT slow because of the GROUP BY or anything else like that. It is really very simple. WHERE is evaluated against the source tables and HAVING is applied against the result set of records. So if you put an expression in HAVING that could be put in the WHERE it takes longer, why? Becuase VFP must get all of the records into the result first and then apply the HAVING condition to that interim result and fitler out the unwanted records. The WHERE clause filters the records out before they ever get into the interim result set.

The issue with the GROUP BY is simply a "rule of thumb", that being, If there is no GROUP BY then there should be no HAVING. But this "rule of thumb" is not always true. HAVING is required to filter on anything that is not found in the source tables. Usually a GROUP BY is present when a SELECT is creating data elements, but not always. For example;

SELECT Quantity, Price, Quantity*Price AS ExtPrice ...

Any need to filter this query on ExtPrice will require a HAVING clause since ExtPrice does NOT exist in the source table. Of course the filter could be stated as;

... WHERE Quantity*Price > 1000 ...

or whatever.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform