Query logic

Certified Senior Developer

Hey all,

Please provide suggestions for below scenario 

1st row is having a columv value 'GE | SP |US'

2nd row is having column value 'USA | CA'

I need to  query the row which is having US or SP in it . I tried the  approach of looping(US,SP) the query filter using include parameter. But for US, we are getting both the rows. 

Can you please suggest an approach to query the expected result which is 1st row ?

Thanks in advance!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    As suggested by  and  , you should change the database design if possible. If that option is not available, you can try the following query to get the desired result:

    a!queryEntity(
      entity: cons!YD_DT_DEMO,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "OR",
          filters: {
            a!queryFilter(
              field: "name",
              operator: "in",
              value: { "|US", "|US|", "US|" }
            ),
            a!queryFilter(
              field: "name",
              operator: "in",
              value: { "|SP", "|SP|", "SP|" }
            )
          }
        ),
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: - 1)
      ),
      fetchTotalCount: false
    )

    Note: You can write code to generate the value of in parameters { "|US", "|US|", "US|" }.

Reply
  • 0
    Certified Associate Developer

    As suggested by  and  , you should change the database design if possible. If that option is not available, you can try the following query to get the desired result:

    a!queryEntity(
      entity: cons!YD_DT_DEMO,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "OR",
          filters: {
            a!queryFilter(
              field: "name",
              operator: "in",
              value: { "|US", "|US|", "US|" }
            ),
            a!queryFilter(
              field: "name",
              operator: "in",
              value: { "|SP", "|SP|", "SP|" }
            )
          }
        ),
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: - 1)
      ),
      fetchTotalCount: false
    )

    Note: You can write code to generate the value of in parameters { "|US", "|US|", "US|" }.

Children
No Data