From the course: Querying Microsoft SQL Server 2022

Unlock the full course today

Join today to access over 24,200 courses taught by industry experts.

Solution: Write a query with a subquery

Solution: Write a query with a subquery - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2022

Solution: Write a query with a subquery

(upbeat music) - [Instructor] I hope you were able to generate the pivot table results that summarize the number of products in each category. Let's get going with the solution. I currently have the challenge six-start SQL file here on the screen, and I'm just going to execute it right away so we can take a look at the results, and then we'll take a look at the query above. So the results give me two columns. The first one is Category Name and it has the four categories of products. And then we have a count of the Number of Products in each of our categories. Looking up here in the Select statement, we have the first column is the Category Name column and this is coming from the Name field in the Product Category table. The second column is using a Counting function, and it's counting up the number of unique Product IDs from the product table, and it's now putting that as the Number of Products. So that's where these…

Contents