Subject | can i aggregate data to get an unique item? |
---|---|
Author | ndirondello marco |
Post date | 2011-04-11T15:00:27Z |
hi all, i have this 2 tables:
Table_A
{
ID Bigint
Name VarChar
}
Table_B
{
ID BigInt
TARGET_ID fk to table A
}
i need to get this result:
select count(b.Id), a.Name
from Table_A a
join Table_B b
on a.Id = b.Target_Id
group by(a.Id)
but it doesn't works becouse a.Name is not an aggregate function, what's the best way to get it?
thanks (sorry if it is a stupid question, i'm newbie to sql)
Table_A
{
ID Bigint
Name VarChar
}
Table_B
{
ID BigInt
TARGET_ID fk to table A
}
i need to get this result:
select count(b.Id), a.Name
from Table_A a
join Table_B b
on a.Id = b.Target_Id
group by(a.Id)
but it doesn't works becouse a.Name is not an aggregate function, what's the best way to get it?
thanks (sorry if it is a stupid question, i'm newbie to sql)