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
)

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 ...

3,026 views 12 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