Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need select statement
Message
From
29/04/2002 13:46:05
 
 
To
29/04/2002 09:31:30
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00650340
Message ID:
00650508
Views:
17
Do it with a subquery.

SELECT a.*, (
SELECT ISNULL(count(*), 0)
FROM b INNER JOIN c ON b.id = c.b_id
WHERE b.a_id = a.id) AS c_count
FROM
a

-Mike

>Hi,
>
>What is easiest way to accomplish the following?
>
>Straight Parent.Child relationsships A -> B -> C
>- records may or may not exist in B that belong to A (0-n)
>- records may or may not exist in C that belong to B (0-n)
>
>What I want is slick little select statement that will list ALL the 'A' records and a count of how many records exist downstream in 'C' for each 'A' record, whether that be 0,1, or whatever
>
>What is best way to accomplish this?
>
>TIA,
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform