Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: How To (Forms, Reports, and more) > Queries/Views > Query Builder > Technical Documents

Building Queries Using GROUP BY

Scroll Prev Top Next More

A GROUP BY clause groups rows according to the values in one or more columns and sorts the results. GROUP BY consolidates the information from several rows into one row. This results in a table with one row for each value in the named column or columns and one or more values per column. With the GROUP BY the columns can be sorted in ascending or descending order.

 

The columns listed in the GROUP BY clause are related to those listed in the query's selected columns. Any column named in the GROUP BY clause can also be named in the query's selected columns, but any column not named in the GROUP BY clause can be used only in the selected columns if the column is used in a SELECT function (SUM, COUNT, etc.).

 

An optional HAVING clause can also be used with a GROUP BY.

 

HAVING Clause

The HAVING clause determines which rows of data to include based on the results of the GROUP BY clause, and essentially limits the rows affected by the GROUP BY clause.

 

The HAVING clause selects rows that meet one or more conditions from among the results of the GROUP BY clause. HAVING works the same as a WHERE clause with the following exceptions:

 

A WHERE clause modifies the intermediate results of a FROM clause; a HAVING clause modifies the intermediate results of a GROUP BY clause

A HAVING clause can include SELECT Functions