Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Getting sql error stating column4 was not part of Group By

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
tom_mat

New User


Joined: 13 Jul 2005
Posts: 11

PostPosted: Wed Oct 18, 2006 7:50 pm    Post subject: Getting sql error stating column4 was not part of Group By
Reply with quote

Hi,

I have a query where i need to find the sum of a column. Also i need to retrieve a column from the same table which has no relation to this sum column.

Select column1, column2, sum(column3) ,column4
from Table1
group by column1, column2.

When I execute this query, I get sql error stating column4 was not part of Group By.

I did not want to use another sql query to fetch just the column4 from table1.

Hence I went for this query which i doubt is an efficient way to do it:
Select column1, column2, sum(column3) ,column4
from Table1
group by column1, column2,column4


Is there a way to do it through a single SQL query without adding column4 in Group By clause?

Thanks,
Tom
Back to top
View user's profile Send private message

vijayamadhuri

Active User


Joined: 06 Apr 2005
Posts: 180

PostPosted: Wed Oct 18, 2006 10:31 pm    Post subject: Re: Getting sql error stating column4 was not part of Group
Reply with quote

nope!!!!!!!!!!!!
Back to top
View user's profile Send private message
mkarmegam

New User


Joined: 28 May 2006
Posts: 13
Location: USA

PostPosted: Thu Oct 19, 2006 2:59 am    Post subject: Re: Getting sql error stating column4 was not part of Group
Reply with quote

icon_sad.gif Nay!
Back to top
View user's profile Send private message
Yoyoyo

New User


Joined: 19 Sep 2006
Posts: 26

PostPosted: Wed Nov 01, 2006 5:02 pm    Post subject:
Reply with quote

Hey tom_mat,

The rule is...
Except for the columns named in the GROUP BY clause, the SELECT statement must specify any other selected columns as an operand of one of the column functions.

By the way, why you need to find a different method to do the same stuff?

YoYo
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DB2 Program abending without giving a... rahulgarg14 DB2 7 Mon May 29, 2017 8:10 pm
No new posts RMM: scratching a volume that RMM thi... Hervey Martinez IBM Tools 0 Mon May 15, 2017 8:51 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Group Data based on a key Arun Raj DFSORT/ICETOOL 7 Thu Apr 27, 2017 11:29 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us