---
title: "Sample queries - Confluence labels"
canonical: "https://support.appfire.com/space/SQL/74323877/Sample%20queries%20-%20Confluence%20labels"
format: markdown
---
> Macro (aura-html)

> ✅ <span style="color: #000000">These queries works with PostgreSQL and were tested against Confluence 5.10. You may need to adjust slightly for other databases. As with all queries against a product database, you need to define a new read-only data source to access the product's database.</span>

> ✅ <span style="color: #000000">Thanks to Shiran Kleiderman for the initial query and question on extending.</span>

# <span style="color: #000000">Site labels</span>

```sql
select
    name as "Label"
  , count(name) as "Count" 
from CONTENT_LABEL 
left join LABEL 
    on CONTENT_LABEL.labelid = LABEL.labelid 
group by name 
order by name
```

# <span style="color: #000000">Labels for space</span>

```sql
select
    name as "Label"
  , count(name) as "Count" 
from CONTENT_LABEL 
left join LABEL 
    on CONTENT_LABEL.labelid = LABEL.labelid 
left join CONTENT 
    on CONTENT_LABEL.contentid = CONTENT.contentid
left join SPACES 
    on CONTENT.spaceid = SPACES.spaceid 
    where spacekey in ('ds')
group by name 
order by name
```

# <span style="color: #000000">Labels by space</span>

```sql
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 
    on CONTENT_LABEL.contentid = CONTENT.contentid
left join SPACES 
    on CONTENT.spaceid = SPACES.spaceid 

group by spacename, name 
order by spacename, name
```