Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A simple SQL but with the count of the child records
Message
From
20/08/2006 22:44:11
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
20/08/2006 22:14:03
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01147165
Message ID:
01147168
Views:
19
>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)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform