The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

SQL join to show some native fileds along with some custom fields

Julio Mugabe
Contributor
January 20, 2013

In the past, it was easy to write an sql join statement and show pkey from the jiraissue table along with the custom value from the customfieldvalue table because these tables were related. Right now it is a little harder because there is a new table called customfieldoption that stores the customfield values. This table is not directly related to the jiraissue table and make is hard to create a join or subquery to retrieve the desired data. Here is an example of data I want to pull from the jira database:

+---------+-------------+-------------------+--------------+

| key | CUSTOMFIELD1 | CUSTOMFIELD2 | CUSTOMFIELD2 |

+---------+-------------+-------------------+--------------+

| abc-102 | 14812 | new york | xyz |

Please send me an sql statement I would use to show the above data.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
daniel santigosa
January 21, 2013

It depends on customfield you want to display. Data you want to display can be in customfieldoption or customfieldvalue.

To show something like your example you need for example:

SELECT 

    jiraissue.pkey,

    (select 

            customfieldvalue.stringvalue AS NUMBR

        FROM

            customfieldvalue

        WHERE

            customfieldvalue.issue = jiraissue.id

                AND customfieldvalue.customfield = 'xxxx'),

    (select 

            customfieldvalue.stringvalue AS CITY

        FROM

            customfieldvalue

        WHERE

            customfieldvalue.issue = jiraissue.id

                AND customfieldvalue.customfield = 'yyyy'),

    (select 

            customfieldoption.customvalue AS LETTER

        FROM

            customfieldvalue,

            customfieldoption

        WHERE

            customfieldvalue.issue = jiraissue.id

                AND customfieldvalue.customfield = customfieldoption.customfield

                AND customfieldvalue.customfield = 'zzzz')

FROM

    jiraissue


THIS QUERY DISPLAY:

+---------+-------------+-------------------+--------------+

| key | CUSTOMFIELD1(xxxx) | CUSTOMFIELD2(yyyy) | CUSTOMFIELD2(zzzz) |

+---------+-------------+-------------------+--------------+

| abc-102 | 14812 | new york | xyz |

I hope this help you

Mehmet Kazgan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
January 7, 2014

Daniel,

How could I get the following?:

customfield | Issue (with query1) | Issue (with query2)

customfield1| value for issue | value for the issue

customfield2| value for issue | value for the issue

Thanks.

0 votes
mwarton
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
January 7, 2014

Hi Julius,

Not sure exactly what you are doing, but if you install the Intelligent Reports plugin you could load this data into a table in a Word file with no programming involved, and use your data for whichever purpose from there.

Hope it helps,

TAGS
AUG Leaders

Atlassian Community Events