Solved

Limitation of Fields in "Group By " clause

Posted on 1998-08-25
7
539 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
ID: 1089725
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
ID: 1089726
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
ID: 1089727
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 1

Accepted Solution

by:
snydero earned 10 total points
ID: 1089728
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
ID: 1089729
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
ID: 1089730
I have tried and succedded in other way.
0
 

Author Comment

by:Favourites
ID: 1089731
I have tried and succedded in other way.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

808 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