Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Lighter Count Child-Parent?
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01382205
Message ID:
01382212
Vues:
35
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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform