How to select unique rows from DataSubset based on one field

Certified Senior Developer

I have a rule rule expression which returns a datasubset in which the data has repeating rows. Since the data is coming from a view in mysql backend, I want to handle this in appian by getting only unique rows and remove all duplicate rows while still maintaining the paging. The data should be unique for 'stateroomRequestId'. I have tried using union but it does not work with datasubsets and only data

a!queryEntity(
  entity: cons!BUS_ENTITY_REQUEST_VIEW_DETAILS,
  fetchtotalcount: ri!fetchtotalcount,
  query: a!query(
    selection: if(
      rule!APN_isEmpty(ri!selection), 
      null,
      a!querySelection(
        columns: a!forEach(
          items: ri!selection,
          expression: a!queryColumn(
            field: fv!item
          )
        )
      )
    ),
    aggregation: ri!aggregation,
    logicalexpression: a!queryLogicalExpression(
      operator: "AND",
      logicalexpressions: ri!logicalexpressions,
      filters: {
        ri!filters
      },
      ignorefilterswithemptyvalues: true
    ),
    paginginfo: if(
      isnull(ri!paginginfo),
      a!pagingInfo(startIndex: 1, batchSize: 1),
      ri!paginginfo
    )
  )
)

  Discussion posts and replies are publicly visible