Adobe Campaign: How to SELECT DISTINCT on queryDef | Community
Skip to main content
sachind75865377
April 26, 2016
Solved

Adobe Campaign: How to SELECT DISTINCT on queryDef

  • April 26, 2016
  • 5 replies
  • 13688 views

Hi,

We are selecting values from two columns which does not include primary key or unique & binding it to drop down and thus getting multiple values in dropdown.

The code snippet is:

ctx.students = xtk.queryDef.create(

  <queryDef schema="stf:student" operation="select">

    <select>

      <node expr="@firstname"/>

      <node expr="@lastname"/>

    </select>

    <orderBy>

      <node expr="@firstname" sortDesc="false"/>

    </orderBy>

  </queryDef>).ExecuteQuery();

How can we can fetch only DISTINCT records?

Thanks

Sachin

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sumit_Saha

Hi Scahin,

Use the method Countdistinct()

for example:

var query = xtk.queryDef.create(<queryDef schema="nms:broadLogRcp" operation="select">

  <select>        

    <node expr="Countdistinct(@account_id)" alias="total"/>

   </select>

   <where>   

    <condition boolOperator="AND" expr={("@status = '1'")}/> 

   </where>

</queryDef>).ExecuteQuery();

var results = query.broadLogRcp;

logInfo("results count= " +results.total);

This should work...

Happy campaigning

Sumit

5 replies

Adobe Employee
May 3, 2016

Set the attribute district to "true".

<queryDef schema="stf:student" operation="select" distinct="true">

August 17, 2016

For me is not working distinct="true" !!!

var query = xtk.queryDef.create(<queryDef schema="nms:broadLogRcp" distinct="true" operation="select">

  <select>         

    <node expr="count(@account_id)" alias="total"/>

   </select>

   <where>   

    <condition boolOperator="AND" expr={("@status = '1'")}/>  

   </where>

</queryDef>).ExecuteQuery();

var results = query.broadLogRcp;

logInfo("results count= " +results.total);

I have the same number for "totalC"  if I run the query with distinct="true" or without it.

Can somebody explain why?

Thank you!

Sumit_Saha
Sumit_SahaAccepted solution
Level 2
August 19, 2016

Hi Scahin,

Use the method Countdistinct()

for example:

var query = xtk.queryDef.create(<queryDef schema="nms:broadLogRcp" operation="select">

  <select>        

    <node expr="Countdistinct(@account_id)" alias="total"/>

   </select>

   <where>   

    <condition boolOperator="AND" expr={("@status = '1'")}/> 

   </where>

</queryDef>).ExecuteQuery();

var results = query.broadLogRcp;

logInfo("results count= " +results.total);

This should work...

Happy campaigning

Sumit

Sumit_Saha
Level 2
August 19, 2016

Sorry the reply was for bianca78

August 19, 2016

Thank you very much!!!