<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Joining multiple tables - about 3 or more tables in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Joining-multiple-tables-about-3-or-more-tables/m-p/440282#M125183</link>
    <description>&lt;P&gt;Thanks DalJeanis, this makes sense , but what if in the assumption table 2 has a key1 also but those are different values from table 1 but you want to pipe the field for key1 in table 1?&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jun 2018 16:12:15 GMT</pubDate>
    <dc:creator>Bentash</dc:creator>
    <dc:date>2018-06-07T16:12:15Z</dc:date>
    <item>
      <title>Joining multiple tables - about 3 or more tables</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Joining-multiple-tables-about-3-or-more-tables/m-p/440280#M125181</link>
      <description>&lt;P&gt;I have about 4 different tables that i am trying to join&lt;/P&gt;

&lt;P&gt;table 1 and table two have a common id, sys_id&lt;/P&gt;

&lt;P&gt;and when you join those two there is another common field parent_id which is also available in table 3&lt;/P&gt;

&lt;P&gt;in this case how do i join the three tables since table 3 has parent_id and its also in the other two join&lt;/P&gt;

&lt;P&gt;join table1 + table2, using sys_id&lt;BR /&gt;
join [table1+table2] + table 3, using parent_id&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:51:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Joining-multiple-tables-about-3-or-more-tables/m-p/440280#M125181</guid>
      <dc:creator>Bentash</dc:creator>
      <dc:date>2020-09-29T19:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Joining multiple tables - about 3 or more tables</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Joining-multiple-tables-about-3-or-more-tables/m-p/440281#M125182</link>
      <description>&lt;P&gt;Okay, first, the word "join" tends to have the wrong connotation here.  There is a keyword &lt;CODE&gt;join&lt;/CODE&gt; in splunk that represents a particular way of connecting tables.  There are a half dozen &lt;EM&gt;other&lt;/EM&gt; ways to join tables, and &lt;CODE&gt;join&lt;/CODE&gt; is not usually the best.  &lt;/P&gt;

&lt;P&gt;Start by reading this reference ... &lt;A href="https://answers.splunk.com/answers/561130/how-to-join-two-tables-where-the-key-is-named-diff.html"&gt;https://answers.splunk.com/answers/561130/how-to-join-two-tables-where-the-key-is-named-diff.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Then apply the following pseudocode, when every table has a single matching key...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search that selects ALL the records you want from any table 
| fields ... list all the fields you want from any table...
| eval matchfield=case(if it is table 1, the matchfield from table 1, 
       if it is table 2, the matchfield from table 2... etc)
| stats values(*) as * by matchfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;The codes is slightly more complicated when you have a second key somewhere.  This gives you an example of rolling data over from a third record onto the second one before &lt;CODE&gt;stat&lt;/CODE&gt;ing the final answer.&lt;/P&gt;

&lt;P&gt;assumptions - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;table 1 has index=index1,   key1  data1
table 2 has index=index2    key2 (which is the same data as key1) subkey2 (which is the same data as key3) data2 
table 3 has index=index3    key3 (which is the same data as subkey2) data3  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;sample code - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search that selects ALL the records you want from any table 
| fields index key1 key2 key3 subkey2 data1 data2 data3 

| rename COMMENT as "roll data from index3 to index2 records by subkey/key3 then drop index3 records"
| eval subkey2=coalesce(subkey2,key3)
| eventstats values(data3) as data3 by subkey2
| where index!="index3"

| rename COMMENT as "set key1 and stats together all  data from the remaining records"
 | eval key1=case(index="index1", key1, 
       index="index2", key2)
| stats values(*) as * by key1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jun 2018 14:35:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Joining-multiple-tables-about-3-or-more-tables/m-p/440281#M125182</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-06-07T14:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: Joining multiple tables - about 3 or more tables</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Joining-multiple-tables-about-3-or-more-tables/m-p/440282#M125183</link>
      <description>&lt;P&gt;Thanks DalJeanis, this makes sense , but what if in the assumption table 2 has a key1 also but those are different values from table 1 but you want to pipe the field for key1 in table 1?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 16:12:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Joining-multiple-tables-about-3-or-more-tables/m-p/440282#M125183</guid>
      <dc:creator>Bentash</dc:creator>
      <dc:date>2018-06-07T16:12:15Z</dc:date>
    </item>
  </channel>
</rss>

