1 Replies - 471 Views - Last Post: 16 October 2011 - 09:22 AM Rate Topic: -----

#1 menukadevinda   User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

group by doesnt work

Posted 16 October 2011 - 07:43 AM

Hi all,

group by doesnt work.
here is the code for table

CREATE TABLE [dbo].[studentPreference](
[id] [int] IDENTITY(1,1) NOT NULL,
[indexNo] [int] NOT NULL,
[Major1] [varchar](5) NOT NULL,
[Major2] [varchar](5) NOT NULL
) ON [PRIMARY]

and here is the sql query
SELECT indexNo,Major1, Major2 FROM studentPreference GROUP BY Major1

plz help me
I got the following error
Column 'studentPreference.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

thx in advan

Is This A Good Question/Topic? 0
  • +

Replies To: group by doesnt work

#2 menukadevinda   User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

Re: group by doesnt work

Posted 16 October 2011 - 09:22 AM

select indexNo, Major1,Major2 from studentPreference GROUP BY Major1,major2,indexNo

this worked, I guess that when use GROUP by we have to use aggregate functions if not use all the fields after the GROUP by and we have to put it in the order to grop it

cheers,
MEnuka.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1