Results 1 to 3 of 3
  1. #1
    gap is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2011
    Posts
    12

    query group by over another group by?

    Hello,
    I am new to access sql and got a problem with a query:

    I got a table like:



    theme subtopic

    a fish
    a fish
    a vegetables
    b vegetables
    c fruits
    c fruits
    c fish

    now i want to get the number of subtopics for each theme.
    anyone got an idea how to solve in a query?

    thanx a lot,
    gap

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Code:
    select theme, count([subtopic]) as [Number of Subtopics]
    
    from table
    
    group by theme

  3. #3
    gap is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2011
    Posts
    12
    thank you, but it was a bit more complex. I wanted to count number of different subtopics for each theme. So instead of getting 3 subtopics for theme a, I have to get 2.

    so here my solution for this one:

    SELECT theme, Count(subtopic) AS NumofSubtopic
    FROM
    (SELECT DINSTINCT theme, subtopic
    FROM my_own_table)
    GROUP BY theme;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Group by query
    By anemoskkk in forum Access
    Replies: 1
    Last Post: 04-16-2011, 07:29 AM
  2. Replies: 5
    Last Post: 11-29-2010, 08:16 AM
  3. Group query results
    By shak2 in forum Access
    Replies: 7
    Last Post: 10-20-2010, 02:41 PM
  4. query group by
    By fanfan2 in forum Queries
    Replies: 3
    Last Post: 03-12-2010, 03:07 PM
  5. columns for group detail but not group header?
    By Coolpapabell in forum Reports
    Replies: 0
    Last Post: 08-21-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums