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

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'

Nice thanks:)

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?

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
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,734 views 17 21
Read article

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