Database tables may have columns containing repeated values. There are situations when you only want to get the distinct values, instead of all the data including the repetitions. To obtain the distinct values of entity attributes in OutSystems, you use an aggregate with grouped columns.
To get the distinct values of an entity attribute:
- In an aggregate in the action flow, add the entity;
- On the attribute for which you want to obtain distinct values, click and choose to group by the attribute.
After grouping an attribute in an aggregate, the aggregate only outputs the grouped attributes.
In the GoOutWeb application, an application to review and rate places, we want to know the end-users that have reviews reported as inappropriate. Since an end-user can have multiple reviews reported as inappropriate, we want to fetch only the distinct end-users:
- Create a new aggregate and drag the entities Review and ReviewReport from the Data tab to the aggregate;
- In the Sources panel, update the join condition to
Review Only With ReviewReportso that the aggregate only fetches reviews that were reported as inappropriate;
- On the Review.UserId attribute, click and select Group by UserId. The aggregate will return only the distinct values of the Review.UserId attribute.