Solved

Limitation of Fields in "Group By " clause

Posted on 1998-08-25
7
540 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

751 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