Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

SQL - Get all labels in per Space - Excluding Personal Spaces.

Michael Schultz February 20, 2020

Currently I have this SQL which returns all spaces, their labels and how many times that label is used. This is great other than the fact that it also returns personal spaces. How can I tweak this SQL to filter out personal and only return global spaces?

 

select
spacename as "Space"
, name as "Label"
, count(name) as Count
from CONTENT_LABEL
left join LABEL
on CONTENT_LABEL.labelid = LABEL.labelid
left join CONTENT

1 answer

1 accepted

0 votes
Answer accepted
Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2020

Hi @Michael Schultz 

I think, this is what you need:

select c.spaceid, s.spacename, l.name, count(l.name) as Count from content_label cl
join CONTENT c on c.contentid = cl.contentid
join label l on l.labelid = cl.labelid
join spaces s on s.spaceid = c.spaceid
where c.CONTENT_STATUS != 'deleted' and c.contenttype != 'SPACEDESCRIPTION' and s.spacetype != 'personal'
group by c.spaceid, s.spacename, l.name
order by count desc

 Regards, Dominic

Michael Schultz February 21, 2020

This works create! Thank you @Dominic Lagger 

Do you know where I can find a database map or sorts for Confluence? Wondering what reference you use when creating SQL like this.

Dominic Lagger
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 24, 2020

Hi,

My reference is the database itself :) I also didn't find some schema or documentation.  

I once went through all tables and analyzed their contents :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events