Hi all..
i'm working with asp.net c#..
i want to make a chart that can retrieve the data from the database..
i found one website that tell the way to make it but i dont understand the query used..
this the the link http://www.dotnetcurry.com/ShowArticle.aspx?ID=238 and the query is

SELECT CategoryName, COUNT(*) AS ProductCount FROM Products JOIN Categories ON Products.CategoryID = Categories.CategoryID GROUP BY CategoryName

anyone can help me translate this query..

1) COUNT(*) is count for the productCount or categoryName?
2) is it necessary to include the join?
3) ProductCount is the attribute that we need to create to pu the result or one of the field in the table in databse?

1). look at your group by, that will tell you what is being counted, unless there is a column name in the Count(). in this case, it's CategoryName.
2) Does the Product table contain a column CategoryName? If it does not (which it shouldn't unless this is a custom view), then yes the join is needed.
3) ProductCount is an alias. when you run a query like this without the alias, the column containing the counted category namaes will not have a column name. by Aliasing the column you have effectively given it a column name that can be used when you pull the data into your application.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.