Adobe Campaign: How to SELECT DISTINCT on queryDef

Avatar

Avatar

sachind75865377

Avatar

sachind75865377

sachind75865377

26-04-2016

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Sumit_Saha

Avatar

Sumit_Saha

Sumit_Saha

18-08-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

Answers (4)

Answers (4)

Avatar

Avatar

Philippe_Ferdin

Employee

Avatar

Philippe_Ferdin

Employee

Philippe_Ferdin
Employee

03-05-2016

Set the attribute district to "true".

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

Avatar

Avatar

bianca78

Avatar

bianca78

bianca78

19-08-2016

Thank you very much!!!

Avatar

Avatar

Sumit_Saha

Avatar

Sumit_Saha

Sumit_Saha

18-08-2016

Sorry the reply was for bianca78

Avatar

Avatar

bianca78

Avatar

bianca78

bianca78

17-08-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!