SQL Query : Retrieve a list of subtask with type of subtask from jira_issue

I had posted same query some time back on the forum , however did not find appropriate response, thus trying again.

I need to find out how to get a list of subtask associated with a bug? I am not able to understand issuelinktype table for achieving this. If anyone has done this in past please share.

Thanks in advance.

1 answer

1 accepted

7 votes

Like this:

select p.pkey as parentkey, c.pkey as childkey, c.issuetype
from issuelink 
inner join jiraissue p on issuelink.source = p.id
inner join jiraissue c on issuelink.destination = c.id
inner join issuelinktype t on issuelink.linktype = t.id
where t.linkname = 'jira_subtask_link'

Yep, points please! Ie mark correct and vote up, thanks.

hi Jamie,

I built following query based on your response, however I need resolution,issuestatus for subtask not for parent key, can you please help :

here : (abc-123 is parent key), if def-456 is subtask, it should show resolution, label for the subtask not for parent key.

select p.pkey as parentkey,p.reporter,p.assignee,p.summary,p.created,
p.resolutiondate, c.pkey as certification_ticket, c.issuetype, r.pname as resolution
,istat.pname as issuestatus
,lb.label
from issuelink
inner join jiraissue p on issuelink.source = p.id
inner join jiraissue c on issuelink.destination = c.id
inner join issuelinktype t on issuelink.linktype = t.id
inner join resolution r on p.resolution = r.id
inner join issuestatus istat on p.issuestatus = istat.sequence
inner join label lb on p.id = lb.issue
where t.linkname = 'jira_subtask_link'
and p.pkey in ('abc-3')
and c.issuetype in ('13')
order by c.pkey,lb.label;

Just change your join of the resolution and label tables to join with the child instead of the parent.

select p.pkey as parentkey,p.reporter,p.assignee,p.summary,p.created,
p.resolutiondate, c.pkey as certification_ticket, c.issuetype, r.pname as resolution
,istat.pname as issuestatus
,lb.label
from issuelink
inner join jiraissue p on issuelink.source = p.id
inner join jiraissue c on issuelink.destination = c.id
inner join issuelinktype t on issuelink.linktype = t.id
inner join resolution r on c.resolution = r.id
inner join issuestatus istat on p.issuestatus = istat.sequence
inner join label lb on c.id = lb.issue
where t.linkname = 'jira_subtask_link'
and p.pkey in ('abc-3')
and c.issuetype in ('13')
order by c.pkey,lb.label;

Thanks Cedric, How do I join issuestatus, should it be : c.issuestatus = istat.sequence?

Join on issuestatus.id

can someone help on this:

for 1706 issuenum, there are 3 subtask... this query returns 3 subtask but return data is commons(that's the 3 rows with 1706 data)

select *  from jiraissue jr
join
issuetype isty on isty.id=jr.issuetype
join
project prj on jr.project=prj.id
join
issuelink islk on islk.source=jr.id
where
isty.pname='Request'  and prj.pkey='JIRA' and jr.id = (
select jr.id from jiraissue jr, project prj
where
jr.project=prj.id and prj.pkey='JIRA' and jr.issuenum=1706
)

Hello  ,

 

Please let me know how to get all sub tasks and tasks for a given project , using my sql data base ..

 

Thanks

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

93 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