Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

SQL2 Query

Avatar

Level 1

Hello All,

 

I have a requirement to remove 'order by' on 'created date' and return the results as added in author dialog.

 

For Instance - Query is

 

SELECT p.* FROM [cq:PageContent] AS p WHERE ISDESCENDANTNODE(p, [/content/test/en])  AND p.[cq:template]  = '/conf/test/settings/wcm/templates/test1' AND ( p.[jcr:path] in ('/content/test/en/second/jcr:content','/content/test/en/first/jcr:content') ) 

So, expectation is to get results in the same order (as added in query) -

 

- /content/test/en/second/jcr:content

- /content/test/en/first/jcr:content

 

whereas, In actual, getting the results like this

 

- /content/test/en/first/jcr:content

- /content/test/en/second/jcr:content

 

Any Suggestions ?

 

Thanks !!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @srajput-woolies ,

 

It seems the natural ordering is being applied by default. Is it possible you can apply sorting based on some attribute you are going to fetch from theses nodes as per business requirement?

 

Another solution is to run the query on each node and then add the result.

 

Thanks,

Ritesh Mittal

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @srajput-woolies ,

 

It seems the natural ordering is being applied by default. Is it possible you can apply sorting based on some attribute you are going to fetch from theses nodes as per business requirement?

 

Another solution is to run the query on each node and then add the result.

 

Thanks,

Ritesh Mittal

Avatar

Community Advisor

What's the exact usecase? Maybe instead of using the JCR_SQL2, you can get the resource of that particular path, and then get childrens of that resource?