Fujitsu J2X0-1634-01EN Computer Accessories User Manual


 
[Figure: Example of fetching data by grouping a table]
The reader probably already noticed in Figure: Example of a table derived from GROUP BY clause that the result of
specifying only a grouped column in the select column list is the same as specifying "DISTINCT" in the query
specification. In Example 2, only PRODUCT was specified in the select column list, so PRODUCT was obtained with
duplicate rows deleted. However, if the objective is to delete duplicate rows, specify DISTINCT rather than specifying
the GROUP BY clause to improve the processing efficiency of the SQL statements.
To fetch the result of a set function and a column name as in Example 2, a table must be grouped. If the set function
and column name are specified in the select column list but the GROUP BY clause is not specified, an error occurs.
The following is an example in which an error occurs:
Example 3:
In this example, a set function is incorrectly used.
SELECT PRODUCT, SUM (STOCKQTY) FROM STOCKS. STOCK
74