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 vote
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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

798 views 2 19
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