Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group By query

Status
Not open for further replies.

Idee

Programmer
Jul 8, 2003
51
NZ
SELECT ProductGroupId,ObjectId,GroupName,Featured,Hidden,CreatedOn,DisplayOrder, count(productid) as cnt
FROM ProductGroup a, product b
WHERE ObjectId = 31
a.productgroupid = b.productgroupid
GROUP BY a.Productgroupid

This query is not correct because Groupby is only on one field and the fieldnames selected are many. But I want all this info along with number of products in each productgroup.

Could anyone help me?

Thanks
 
Hi

Cannot give definitive answer, but you need to apply an agregate condition to each of the other selected fields so (I have given example of First() for ObjectId, you need to decide which functions you want to apply and apply them to teh remaining seelcted columns

SELECT ProductGroupId,First(ObjectId) As FisrtObjectId,GroupName,Featured,Hidden,CreatedOn,DisplayOrder, count(productid) as cnt
FROM ProductGroup a, product b
WHERE ObjectId = 31
a.productgroupid = b.productgroupid
GROUP BY a.Productgroupid



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top