Adding a constant value column in the group by clause

Victor picture Victor · Feb 7, 2014 · Viewed 16.1k times · Source

Netezza sql is giving error on this query:Cause: Invalid column name 'dummy'.

 select col1,col2, '' as dummy, max(col3) from table1  group by col1,col2,dummy

If i remove the dummy from the group by clause, it works fine. But as per sql syntax, I am supposed to include all non aggregate columns in group by.

Answer

Maryam Arshi picture Maryam Arshi · Feb 7, 2014

why do you need it in your group by, you can use an aggregate function and its result would always be right because the value is constant for example:

select col1,col2, min(' ') as dummy, max(col3) from table1  group by col1,col2