Link to home
Start Free TrialLog in
Avatar of Krapulator
Krapulator

asked on

DISTINCT Query with totals

I have a table with a "Cat" field and a "SubCat" field.

I need a SQL query which returns the distinct SubCats for a given Cat and the total number of SubCats found for each distinct SubCats

My Table:

Cat                    Subcat          
--------              ----------
1                        1
1                        2
1                        3
1                        3


I want the query to return the distinct Subcats with totals for the given cat. Thus if my Cat was 1 as in the above example, I want the query to return:

Subcat           Total
--------           ---------
1                   1
2                   1
3                   2
Avatar of nmcdermaid
nmcdermaid

something like this:


SELECT COUNT(*) As Total, SubCat
FROM Table
GROUP BY SubCat
ASKER CERTIFIED SOLUTION
Avatar of nmcdermaid
nmcdermaid

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Krapulator

ASKER

Perfect. Thanks!