Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A simple SQL but with the count of the child records
Message
De
20/08/2006 22:44:11
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
20/08/2006 22:14:03
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
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01147165
Message ID:
01147168
Vues:
23
>I have a one to many relationship. From the master table, I am selecting all the records. But, for each record in the SQL result, I need to also include the number of child records. Anyone would have a quit example on how to achieve that?

I think the basic idea is something like this:
select Master.Master, count(*) as HowMany;
  from Master join Child on Master.Master = Child.Master;
  group by Master;
  into cursor Temp
Additional adjustments may be needed if there is the possibility of master records without child records. A left join, for a start.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform