SQL2 Query | AEM

Fetch users node

SELECT * FROM [rep:User] As user WHERE ISDESCENDANTNODE(user, ‘/home/users’) AND [rep:authorizableId] <> ‘anonymous’ AND [jcr:primaryType] <> ‘rep:SystemUser’ AND [rep:authorizableId] NOT LIKE ‘%@%’ ORDER BY [rep:authorizableId] ASC

Search node having specific resourceType

SELECT * FROM [nt:unstructured] As node WHERE ISDESCENDANTNODE(node, ‘/content’) and [sling:resourceType] LIKE  ‘%components/page/site’

Find the pages which does not have [cq:tags] property

select * from [cq:PageContent] as page where ISDESCENDANTNODE(page,’/content/corporate/news’) AND page.[cq:tags] is null

Find the page and its node who has matching component

select * from [nt:unstructured] as page where ISDESCENDANTNODE(page, ‘/content’) and [sling:resourceType] like ‘%components/content/accordion’

Find the projects/Website name where the specific component is exist

select * from [cq:Component] as node where ISDESCENDANTNODE(node, ‘/apps’) and name() =’accordion’

Find the template name where particular component is used

select * from [nt:unstructured] as page where ISDESCENDANTNODE(page, ‘/apps’) and [sling:resourceType] like ‘%accordion’

Find all templates in apps folder

select * from [cq:Template] as page where ISDESCENDANTNODE(page, ‘/apps’)

Find all pages which created by specific template

select * from [cq:PageContent] as page where ISDESCENDANTNODE(page, ‘/content/corporate’) and [cq:template] =’/apps/corporate/templates/home-page’