List of Projects, Project Categories, and Project Leads

I am working on a SQL query to extract the projects their leads and the project category. I was able to extract this with the below query

select pc.id,pc.cname, p.id, p.pname from nodeassociation na, projectcategory pc, project p
where na.sink_node_id=pc.id and
na.source_node_id=p.id and
na.sink_node_entity='ProjectCategory' and
na.association_type='ProjectCategory'
order by pc.cname;

OR

select p.id, p.pname, p.lead, na.sink_node_id, na.sink_node_entity, pc.cname from jiradb.jiraschema.project p
left outer join jiradb.jiraschema.nodeassociation na ON na.source_node_id=p.id
Inner join jiradb.jiraschema.projectcategory pc ON na.sink_node_id=pc.id
WHERE
na.sink_node_entity='ProjectCategory' and
na.association_type='ProjectCategory'

but there is a glitch in this. I have some projects which does not have any category my query doesn't extract those projects. I have looked into node association and there is no entry for that project for project category even with value null. It seems kind of not possible to me. If anyone is having a clue of how to do it. Please let me know.

1 answer

0 votes
Alexey Matveev Community Champion Dec 19, 2017

Hello,

Use outer join the get the lines with null values. It would be something like this

select p.id, p.pname, p.lead, na.sink_node_id, na.sink_node_entity, pc.cname from jiradb.jiraschema.project p
left outer join jiradb.jiraschema.nodeassociation na ON na.source_node_id=p.id
left outer join jiradb.jiraschema.projectcategory pc ON na.sink_node_id=pc.id
WHERE
na.sink_node_entity='ProjectCategory' and
na.association_type='ProjectCategory'

Hey Alexey, 

Thank you for response. Even with above query I am getting the exact same result as I was getting with my query, It does not retrieve the project with no category.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,775 views 11 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot