Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WHERE vs JOIN
Message
De
12/09/2005 17:18:40
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
12/09/2005 17:02:47
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
01048959
Message ID:
01048964
Vues:
27
Hi Rich

>In a previous thread I posted a query
>
>SELECT DISTINCT pol.agentcode,pol.ctrl_num,pol.incep_date FROM frpolicy pol;
>  JOIN frlocat loc ON pol.agentcode=loc.agentcode and pol.ctrl_num=loc.ctrl_num;
>  WHERE pol.incep_date >={8/31/2005} AND loc.state='OR'
>
and received a response suggesting
>
You might also consider moving your loc.state='OR' up into the JOIN.
>
>I infer that means it would have been better to write the query as
>
>SELECT DISTINCT pol.agentcode,pol.ctrl_num,pol.incep_date FROM frpolicy pol;
>  JOIN frlocat loc ON pol.agentcode=loc.agentcode and pol.ctrl_num=loc.ctrl_num;
>                   AND loc.state='OR';
>  WHERE pol.incep_date >={8/31/2005}
>
>
>Other than being more "modern", slightly(??) more readable, and having the ability to handle non-matching keys, is there a performance benefit to using JOIN rather than WHERE clauses....ie.
>
>SELECT DISTINCT pol.agentcode,pol.ctrl_num,pol.incep_date FROM frpolicy pol,frlocat loc;
> WHERE pol.agentcode=loc.agentcode and pol.ctrl_num=loc.ctrl_num;
>   AND pol.incep_date >={8/31/2005};
>   AND loc.state='OR'
>
>As an admitted dinosaur, I've always coded using the second style. The few times I've used a JOIN, I've put only items which show the relationship between the tables into the ON clause. I felt that made the code more readable and didn't realize it might impact performance.
>
>So, in general, is there a performance gain from using JOIN rather than WHERE? Is JOIN significantly more readable than WHERE? Is there a benefit to moving the part of the WHERE clause pertaining to the JOINED table into the JOIN expression (sorry for the convoluted expression, but I think you know what I mean).
>
>Thanks to all.........Rich

I can't say for certain if one is faster than another. I would hope that if I'm trying to join only some locations (OR), it would be faster to join with the filtered subset, rather than joining all and filtering after. That way the where clause applies to the main datasource (policy).
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform