Register | Login

Tech Center

Tech Tips

In Teradata, does a GROUP BY clause imply a grouping of similar values when the output is displayed? In other words, if there is no aggregate function, will a GROUP BY clause allow you to see the similar values grouped together as shown below, or do you have to use the ORDER BY clause?

Select ColA, ColB from Tab Group By ColA;
ColA ColB
-------- --------
B 4
B 3
B 2
A 1
A 4
C 5
C 4
C 3


Your example is an incorrect use of the GROUP BY clause, which would result in a semantic error returned from the database. GROUP BY is for aggregation operations, not for ordering rows in the output. If a GROUP BY clause is present, then all columns in the select list must either be listed in the GROUP BY or must be aggregate functions that will be calculated per group.

The proper way to get the result you show above is to use ORDER BY ColA rather than GROUP BY. The data will be sorted in alphabetical or numerical order.

View All Tips >
Got a great idea? Share it with your peers!  >


Company Newsroom Site Help Site Map Privacy/Legal Contact Us