To give some more background on this, I have namespaces defined like this:
Further I have a data type, tb:Post, defined like this as a CND file (this is a simplified version based on the actual definition):
The tb:Post data type is used to create child nodes in the 'pst' namespace. These are attached to a parent node in the 'wall' namespace. The data looks something like this:
So what I wanted to do was select all of the child nodes for say the wall:1 parent. I also wanted to do some sorting based on a property defined in tb:Post, tb:postDate in my case. Getting all the child nodes is simple if you have the parent node already, simply call getNodes() and you're done, but that doesn't sort your results, it also won't let you limit how much data is returned for paging purposes.
So we get to the JCR-SQL2 statement that will meet all of the above criteria...
The above is a bit unintuitive at first because you're selecting from a data type?! Remember JCR doesn't define tables so in that context it makes sense. The where clause filters the data for the parent node using the ID of the parent and the jcr:path pseudo-property. The the sorting is done by tb:postDate.
It looks straight forward after getting it to work!
That simple example can be further built out to include support for pagination by adding the LIMIT clause.