Friday, March 23, 2012

please check

There are 2 tables -
say table 1 - child table - say child
table 2 - parent table - say parent
Assume that each child only resides on a single parent and each parent
may contain multiple children....
Can we write a query for finding how many children are on each and
every parent...?Why are you starting a new thread for the same question?
<chump1708@.yahoo.com> wrote in message
news:1134656162.207875.44300@.o13g2000cwo.googlegroups.com...
> There are 2 tables -
> say table 1 - child table - say child
> table 2 - parent table - say parent
>
> Assume that each child only resides on a single parent and each parent
> may contain multiple children....
> Can we write a query for finding how many children are on each and
> every parent...?
>|||well...thats bcoz the earlier question was confusing and typed wrongly..|||chump1708@.yahoo.com wrote:

> well...thats bcoz the earlier question was confusing and typed
> wrongly..
Did you try my query?
I don't quite understand why the others are giving links to handle this
with self-referenced tables. You said you have 2 tables: one with
children and and with parents. So IMHO there is no need for that.
HTH,
Stijn Verrept.|||Dear Stijin,
select cid, (select count(*) from childTable where gid = cid) as
ChildCount from parentTable
I got with this...why do u use 'as' word ?
and ChildCount - ? - what do u mean how 2 implement this?
All i have is
2 tables
table1 - child ('gid') and
table 2 - parent ('cid'). Each child only resides on a single
parent and each parent may contain multiple children. How do would you
find how many children are on each and every parent?
CAN U PLEASE REWRITE THE CODE>>>>>>|||chump1708@.yahoo.com wrote:

> I got with this...why do u use 'as' word ?
> and ChildCount - ? - what do u mean how 2 implement this?
> All i have is
> 2 tables
> table1 - child ('gid') and
> table 2 - parent ('cid'). Each child only resides on a single
> parent and each parent may contain multiple children. How do would you
> find how many children are on each and every parent?
> CAN U PLEASE REWRITE THE CODE>>>>>>
No need to shout!
It is completely impossible for us to rewrite correct code for you if
you do not provide us with the DLL: check this before asking a
question: www.aspfaq.com/5006
AS is to give the result column a name.
Kind regards,
Stijn Verrept.|||Seriously, have you any experience with T-SQL?
The AS keyword precedes the column alias to be used as the name of the
column in the result set.
ML
http://milambda.blogspot.com/|||select parent, count(1)
from parent p
join child c on p.parentId = c.parentId
group by parent
<chump1708@.yahoo.com> wrote in message
news:1134656162.207875.44300@.o13g2000cwo.googlegroups.com...
> There are 2 tables -
> say table 1 - child table - say child
> table 2 - parent table - say parent
>
> Assume that each child only resides on a single parent and each parent
> may contain multiple children....
> Can we write a query for finding how many children are on each and
> every parent...?
>|||if you want the parent with zero children do the following
select parent, count(1)
from parent p
left join child c on p.parentId = c.parentId
group by parent
"JI" <jidawgs@.hotmail.com> wrote in message
news:%23bFvOhaAGHA.208@.tk2msftngp13.phx.gbl...
> select parent, count(1)
> from parent p
> join child c on p.parentId = c.parentId
> group by parent
> <chump1708@.yahoo.com> wrote in message
> news:1134656162.207875.44300@.o13g2000cwo.googlegroups.com...
>sql

No comments:

Post a Comment