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

This widget could not be displayed.
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 Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

79 views 0 1
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