Solved

Limitation of Fields in "Group By " clause

Posted on 1998-08-25
7
537 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

809 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