1

I have a table that has the following fields:

Name | Category | Description

I want to select all categories and display them like:

Category | Category Count

So how would I do a

SELECT Category FROM MyTable 
UNION
SELECT COUNT(Category)

but have the count show the specific count for that row?

1
  • 1
    I was going to post, but this one is just too basic. Boogada, research the GROUP BY clause, it should give you what you need. Commented Mar 3, 2011 at 2:48

2 Answers 2

7

Try this:

SELECT Category, COUNT(Category) FROM MyTable GROUP BY Category;
Sign up to request clarification or add additional context in comments.

Comments

0

Here is other example without group by function

Select category, count(category) over () from MyTable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.