Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Lighter Count Child-Parent?
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01382205
Message ID:
01382212
Views:
37
It should be other way around because in general a parent record can exists w/o child records.
Select count(tablechild.someid) as itemcount, tableparent.description ;
	from tableparent ;
		left outer join tablechild ;
			on tablechild.someid = tableparent.someid ;
	group by tableparent.someid,tableparent.description
>In a one to many relationship between a parent and child table, what is the lightest way to count() the child table and return the parent description in one SQL statement?
>
>Like:
>TableParent = SomeID I, description C(50)
>TableChild = pk I, SomeID I, OtherTablePK I)
>
>My answer is this:
>
>
>Select count(tablechild.someid) as itemcount, tableparent.description ;
>  from tablechild ;
>    left outer join tableparent ;
>    on tablechild.SomeID=tableparent.SomeID ;
>   group by tablechild.someid,tableparent.description
>
>
>But it seems that I'm missing a "lighter" way to do this... am I?
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform