Results 1 to 3 of 3

Thread: Group by

  1. #1
    Join Date
    Feb 2009
    Posts
    5

    Group by

    I am trying to run the following query:
    select distinct inc_major_sc,inc_cat_sc from inc_cat
    inner join inc_major on inc_major.inc_major_id = inc_cat.inc_major_id
    where inc_cat_sc not in
    ((select
    inc_cat.inc_cat_sc
    from
    inc_cat inner join incident on incident.cause_id = inc_cat.inc_cat_id
    where
    inc_cat.inc_cat_id <> 0)
    union
    (select
    inc_cat.inc_cat_sc
    from
    inc_cat inner join incident on incident.inc_cat_id = inc_cat.inc_cat_id
    where
    inc_cat.inc_cat_id <> 0))
    GROUP BY inc_major.inc_major_sc

    I am getting this error:
    Msg 8120, Level 16, State 1, Line 1
    Column 'inc_cat.inc_cat_sc' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    What exactly is this error telling me and how do I group this by the inc_major_sc?

    Thanks in advance for your assistance,
    Di-

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Have to add it in group by clause.

  3. #3
    Join Date
    Feb 2009
    Posts
    5
    Thanks for the quick response.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •