Ahmed Skaik
Ahmed Skaik

Reputation: 23

exclude a column from group by statement

I would like to exclude a column from group by statement, because it results in some redundant records. Are there any recommendations?

I use Oracle, and have a complex query which join 6 tables together, and want to use sql aggregate function (count), without duplicate result.

field to be ecxclude

Upvotes: 1

Views: 971

Answers (1)

Ben
Ben

Reputation: 52863

You can't.

When using aggregate functions every column/column expression which is not an aggregate must be in the GROUP BY.

This is completely logical. If you're not aggregating the column then excluding it from the GROUP BY would force Oracle to chose a random value, which is not very useful.

If you don't want this column in your GROUP BY then you must decide what aggregation to apply to this column in order to return the appropriate data for your situation. You can't hand this responsibility off to the database engine.

Upvotes: 3

Related Questions