JIRA SQL query to get Epics with a specific fixVersion

I'm on JIRA 7.2 with MySQL and need to write a SQL query for a Confluence macro and all I need to do is to get all the Epics from a specific project with a specific fixVersion but can't seem to grasp it.

Here's what I have so far, but it's returning all 429 Epics in the project, not just the 98 Epics in the project with fixVersion 'Twinkies'.

SELECT count(issuenum)
FROM jiraissue 
join issuetype on jiraissue.issuetype=issuetype.ID
join projectversion on jiraissue.project=projectversion.project
where issuetype.id = 10001
and projectversion.project = 11604
and projectversion.vname = "Twinkies"

1 answer

This widget could not be displayed.
Tayyab Bashir Community Champion Oct 31, 2017

Hi,
It returns all the epics because you have a where you are getting issues which have type epics AND they belong to a project which has a version named "Twinkies".

So that's not the correct approach. 
You will need to look into nodeassociation table

It will be able to give you what you're looking for. 
For more, read this Knowledge Base

Thank you - We were able to resolve the query using that advice.  Here is the solution:

SELECT count(ji.issuenum)
FROM jiraissue ji
INNER JOIN nodeassociation na ON na.SOURCE_NODE_ID = ji.ID AND
na.ASSOCIATION_TYPE = 'IssueFixVersion'
INNER JOIN projectversion pv ON ji.PROJECT=pv.PROJECT AND pv.ID =
na.SINK_NODE_ID
WHERE ji.issuetype = '10001'
AND pv.PROJECT = '11604'
AND pv.vname='Twinkies'

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 12 hours ago in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

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