Solved

Limitation of Fields in "Group By " clause

Posted on 1998-08-25
7
536 Views
Last Modified: 2006-11-17
I am having a query which consists of 40 fields from a
single table. I need to group on all the 40 fields in my
"SELECT" query. If I include all of them in my query,
in the "group by" clause, I get an error message which says,
"there is a limtation of only 16 fields in a "Group By" clause."

How will I include the rest of the fields in the "Group By"
clause ? Can I increase the limitations by setting options
(if any) in the client/server machine ?


Looking forward for a postive response and kind co-operation.
0
Comment
Question by:Favourites
7 Comments
 
LVL 3

Expert Comment

by:sidcap
Comment Utility
Try to include in the "Group By" clause only the fields that you  really need to group ( generally, as maximum they are about 4 ); for  the rests of the SELECT fields you must need to apply them some grouping function like MAX(field), MIN(field), LAST(field).

Hope  this help !
SIDCAP.
0
 

Expert Comment

by:shaloo
Comment Utility
Favourites, enough of yuor 40 fields are text fields that you can concatinate them (creating temp expressions) resulting in less than 16 fields to GROUP BY on.  And no, I know of no way to increase the setting options
0
 

Author Comment

by:Favourites
Comment Utility
Assume that I have 45 fields in a table.
I am forced to have 40 fields out of 45 in my GROUP BY clause.
which is also present in SELECT clause.

In this case, how will include them in my GROUP BY clause ?
Give me an illustration of the above case.


0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Accepted Solution

by:
snydero earned 10 total points
Comment Utility
The answer is --> VIEWS!
Create several views of your 45 column table, each with a group by clause like this...
CREATE VIEW first_part AS SELECT
  col1,
  col2,
  ...
  col16
GROUP BY col1, col2,... col16
GO   -- <-- This GO must be here for the next line to work!!
CREATE VIEW second_part AS SELECT
  col17,...

Then select from you views.  You will also need to include the primary key of the 45 column table in each of the views so you can link all those views together in your final select.

0
 

Expert Comment

by:shaloo
Comment Utility
Syndero,  JOINing several VIEWS with their own GROUP BY clauses will not give you the same result as doing GROUP BY on all those fields simulatneously.  Additionally, including the PRIMARY key in the VIEW will defeat the value of GROUP BY.

Favourites, if you have to see the fields AND group by them, then I think you are out of luck.  It just cannot be done by SQL.  You will have to create a temporary table and populate the values using multiple queries.  My suggestion above is only if you wanted GROUP BY but did not need to see them.
0
 

Author Comment

by:Favourites
Comment Utility
I have tried and succedded in other way.
0
 

Author Comment

by:Favourites
Comment Utility
I have tried and succedded in other way.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now