Table Transformer - Select Through Multiple Items Within Key Cell - Unable to Join Tables
Asked by Emily Berg:

Good morning community!

I am trying to join two tables together, but my 'key' contains multiple items within a given cell. Is there a way to index through each item within the cell to check for a match / join?

In the top table key SR-3679 is "tested by" three different "TER" links. The bottom table provides the details for the individual "TER" issues. I need to be able to either:

1. Create a table with 3 separate rows for SR-3679 showing the details of each "tested by" TER OR
2. Create a table and merge the details of all TER within the single SR-3679 row

Any suggestions, please!![image.png](/t5/image/serverpage/image-id/137053i6882F07EA6F35A97/image-size/large?v=v2&px=999 "image.png")


Answers:
author: Katerina Kovriga {Stiltsoft}
body: Hi [@Emily Berg](/t5/user/viewprofilepage/user-id/4210574) ,

We've recreated your case here:

![Thu 6-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/137096iB02867F942E8792D/image-size/large?v=v2&px=999 "Thu 6-1.png")

If you have the only one type of keys (**TER**-XX), then we suggest using the following SQL query (it will be a more reliable one):

SELECT \* FROM T1  
LEFT JOIN T2 ON T1.'Tested by'-\>split("TER-")-\>indexOf(REPLACE(T2.'TER Key', "TER-", "")) \> -1

![Thu 6-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/137097iB9327625A494CE1C/image-size/large?v=v2&px=999 "Thu 6-2.png")![Thu 6-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/137098i514731A1721A7257/image-size/large?v=v2&px=999 "Thu 6-3.png")If you have other types of projects (keys), then you may use a simpler query:

SELECT \* FROM T1  
LEFT JOIN T2 ON T1.'Tested by'-\>indexOf(T2.'TER Key') \> -1

Hope this helps your case.

comments: author: Emily Berg
body: [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) ,

This is AWESOME! Thank you very much for the response! Could you elaborate on why the first solution would be more reliable (for my own edification)?

Emily


author: Katerina Kovriga {Stiltsoft}
body: The first variant splits and then joins your keys strictly - as you can see, there is the name of your project "TER-" included into the 'split' and 'indexOf' sql functions.

If you work with another project, then you'll have other keys (for example, WER-13, WER-15, etc.) and put "WER-" for 'split' and 'indexOf' functions.

The second variant is a more general and simple one. It works, but the result table should be checked manually at first if you have multiple project names with similar key indexes to prevent any mismatching.


author: Emily Berg
body: Thank you [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) ,

As you pointed out, the general approach is less robust and I am now seeing an issue because of similarities with other keys.

I have another problem regarding this request - my key field is not just "TER-", rather its a custom field that contains other text, e.g. "TER-XXX \| Status \| Summary". How would I break out just the key from this field in order to proceed with the split function mentioned above?

Emily


author: Katerina Kovriga {Stiltsoft}
body: Hi [@Emily Berg](/t5/user/viewprofilepage/user-id/4210574) ,

Not to mess up the original query, I suggest wrapping your second table with the combined TER Key into a separate Table Transformer:

![Fri 1-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/141376i5CBFE7A3F9D9D265/image-size/large?v=v2&px=999 "Fri 1-1.png")

Use the following SQL query to split your strings by the " \| " symbols:

SELECT T1.'TER Key'-\>split(" \| ")-\>0 AS 'TER Key',  
T1.'TER Key'-\>split(" \| ")-\>1 AS 'Description',  
T1.'TER Key'-\>split(" \| ")-\>2 AS 'Description2',  
T1.'TER Summary'  
FROM T\*

![Fri 1-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/141377i3CAB1BC6A742FB53/image-size/large?v=v2&px=999 "Fri 1-2.png")

![Fri 1-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/141378iFA9C213B434E90EE/image-size/large?v=v2&px=999 "Fri 1-3.png")

And here is the result table for the first Table Transformer with the original SQL query:

![Fri 1-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/141379i4880E5D6577572A5/image-size/large?v=v2&px=999 "Fri 1-4.png")

Hope this helps.


author: Emily Berg
body: Works like a charm!

You're the best [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) !

Emily


author: Emily Berg
body: [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) ,

Now that I have expanded my use of this query, I am running into another issue. I am getting partial matches when using the index query.

I have two tables:

One containing "Key", "Summary", "Tested By", and "Tested-By-Key"

One containing "TER Key" and "TER Summary".

I am using the following query to merge the two tables based on the T1.'Tested-By-Key' to T2.'TER Key':

SELECT \* FROM T1  
LEFT JOIN T2 ON T1.'tested-by-key'-\>indexOf(T2.'TER Key') \> -1

For this example, there should only be one match - IVDTER-168, but a partial match of IVDTER-16 is also appearing in the joining operation. Is there a different query that enables an exact match only?

Thank you,

Emily![2021-07-26_11-45-16.png](https://community.atlassian.com/t5/image/serverpage/image-id/152940iB39116CEAC87BA1B/image-size/large?v=v2&px=999 "2021-07-26_11-45-16.png")


author: Katerina Kovriga {Stiltsoft}
body: Hi [@Emily Berg](/t5/user/viewprofilepage/user-id/4210574) ,

I think we should stick to the more specific SQL query that I mentioned first - the one that includes the name of the project.

If I remember your case right, you are trying to merge the two tables that look similar to this screenshot:

![Mon 3-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/152952i9E2C3E1DF98BEC15/image-size/large?v=v2&px=999 "Mon 3-1.png")

The second table was divided by the internal Table Transformer macro:

![Mon 3-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/152953i2DD2AF936BEA283B/image-size/large?v=v2&px=999 "Mon 3-2.png")

Now try to merge these two tables with the help of the following SQL query:

![Mon 3-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/152954i79BBCDE20F90D3EF/image-size/large?v=v2&px=999 "Mon 3-3.png")

SELECT \* FROM T1  
LEFT JOIN T2 ON  
T1.'Tested-by-key'-\>split("TER-")-\>indexOf(REPLACE(T2.'TER Key', "TER-", ""))\>-1

![Mon 3-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/152955i0137B07B2AD1A3F7/image-size/large?v=v2&px=999 "Mon 3-4.png")

As you can see, the TER-16 and TER-11 cells (with the orange background) weren't matched to the TER-168 and TER-118 by partial match.


author: Emily Berg
body: Hi [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) ,

Thank you for the fast reply. This does work - but what about cases where the prefix ("TER-") is not always the same? I could do a case within the query to extract just the number, but then I could get duplicates depending on the prefix...e.g. TER-147 and IVDTER-147. Thoughts with this use case?

Thanks,

Emily


author: Katerina Kovriga {Stiltsoft}
body: I'll consult with our developers tomorrow and get back to you - can't come up with a better idea for the case with different prefixes.

As a straightforward workaround, you may use several Transformers - each one for every prefix (I assume that one or both of your tables come from the Jira Issues macro, so you may filter and process every project separately). The result table could be combined using an additional Transformer with a standard Merge preset.


author: Katerina Kovriga {Stiltsoft}
body: Hi [@Emily Berg](/t5/user/viewprofilepage/user-id/4210574) ,

Here I am with a rather complex SQL query from our developers:

![Thu 1-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/153108iBD735F76EE9058D2/image-size/large?v=v2&px=999 "Thu 1-1.png")

![Thu 1-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/153109i76A5DC81515C94C4/image-size/large?v=v2&px=999 "Thu 1-2.png")

SELECT \* FROM T1  
LEFT JOIN T2 ON  
T1.'Tested-by-key'-\>match("(\^\|\[0-9\])" + T2.'TER Key' + "(\[\^0-9\]\|$)")

![Thu 1-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/153110i2899E1D081375F11/image-size/large?v=v2&px=999 "Thu 1-3.png")

As far as I can see, the query matches your case.


author: Emily Berg
body: Yes, this is beautiful! Thank you to [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746) and your team!

Emily


author: K?ntor Tibor
body: Are these tables a result of JIRA filters?

Anyway, if I understood your question right, then this might help:

You already have the table for SR issues (let this be T1)

Filter and create a separate table for all TER issues affected in your SR table(let this be T2), then with these 2 tables in the same table transformer macro:

```
SELECT
(SELECT T1.'Key' FROM T1 WHERE T2.'TER Key' IN T1.'Tested By') AS 'SR Key',
T2.'TER Key',
T2.'TER Summary',
...
any other columns
...
FROM T2
```

This way you will have something like this:

![ter.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/137061i0A5CE718A13C1010/image-size/large?v=v2&px=999 "ter.PNG")

comments: author: Emily Berg
body: [@K?ntor Tibor](/t5/user/viewprofilepage/user-id/3625586) - Thanks for the response. This works only for the first row of T1 data. I need to be able to loop this function through a large T1 with multiple rows. Is there a way to incorporate a while loop or something similar to index through the entire T1 table?


author: K?ntor Tibor
body: Not sure why... I have the same setup, separating linked issues to different rows, and it loops through the whole T1 table. Might not be a while loop issue?


Tags: confluence-server

macro

server

table-transformer