<?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 How to combine two searches with common value into one table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497485#M138557</link>
    <description>&lt;P&gt;I need help regarding a join from events based on different sourcetype (same index) that are related by the same value in different fields.&lt;BR /&gt;
The logical flow starts from a bar char that group/count similar fields. With drill down I pass the 'description' by a token to the search that has to combine the search into a table. &lt;BR /&gt;
Below a simple example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype_A
s1_field1 = Purchase OK
s1_field2 = 9
s1_field3  = tax value
s1_field4 = Completed

sourcetype_B
s2_field1 = 9
s2_field2 = Rome
s2_field3 = Fontana di Trevi
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to obtain a table with fields "s1_field2, s1_field1,s2_field2,s2_field3"&lt;/P&gt;

&lt;P&gt;I'm working around this kind of search without obtaining my outcome.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="Sourcetype_A" s1_field4="Completed" | search s1_field1=$from_token$
| join s1_field2
    [ search sourcetype="Sourcetype_B" 
    | rename s2_field1 as s1_field2 ] 
| table s1_field2, s1_field1,s2_field2,s2_field3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank in advance for your help.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 03:11:43 GMT</pubDate>
    <dc:creator>gballanti</dc:creator>
    <dc:date>2020-09-30T03:11:43Z</dc:date>
    <item>
      <title>How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497485#M138557</link>
      <description>&lt;P&gt;I need help regarding a join from events based on different sourcetype (same index) that are related by the same value in different fields.&lt;BR /&gt;
The logical flow starts from a bar char that group/count similar fields. With drill down I pass the 'description' by a token to the search that has to combine the search into a table. &lt;BR /&gt;
Below a simple example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype_A
s1_field1 = Purchase OK
s1_field2 = 9
s1_field3  = tax value
s1_field4 = Completed

sourcetype_B
s2_field1 = 9
s2_field2 = Rome
s2_field3 = Fontana di Trevi
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to obtain a table with fields "s1_field2, s1_field1,s2_field2,s2_field3"&lt;/P&gt;

&lt;P&gt;I'm working around this kind of search without obtaining my outcome.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="Sourcetype_A" s1_field4="Completed" | search s1_field1=$from_token$
| join s1_field2
    [ search sourcetype="Sourcetype_B" 
    | rename s2_field1 as s1_field2 ] 
| table s1_field2, s1_field1,s2_field2,s2_field3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank in advance for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:11:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497485#M138557</guid>
      <dc:creator>gballanti</dc:creator>
      <dc:date>2020-09-30T03:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497486#M138558</link>
      <description>&lt;P&gt;You need &lt;CODE&gt;selfjoin&lt;/CODE&gt;, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults
| eval raw="sourcetype=sourcetype_A,s1_field1=PurchaseOK,s1_field2=9,s1_field3=taxvalue,s1_field4=Completed sourcetype=sourcetype_B,s2_field1=9,s2_field2=Rome,s2_field3=FontanadiTrevi"
| makemv raw
| mvexpand raw
| rename raw AS _raw
| kv

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| eval joiner=coalesce(s1_field1, s2_field1)
| selfjoin joiner
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Dec 2019 16:46:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497486#M138558</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-05T16:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497487#M138559</link>
      <description>&lt;P&gt;You'll see this answer a lot on here.  You should avoid joins except for some very specific use cases.  Joins are inefficient and can cause  truncation of your data results, since it has a default limitation of only running for 30 seconds and then auto finalizing.  I suggest doing this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(sourcetype="Sourcetype_A" s1_field4="Completed") OR sourcetype="Sourcetype_B" 
| eval joiner=if(sourcetype="Sourcetype_A", s1_field2, s2_field1)
| stats values(*) as * by joiner
| where s1_field2=s2_field1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Season the above query to taste by only putting the fields you want in the third line.  What this is doing is pulling in both data sets and joining them together with a stats command.  This is won't run into those timing limitations that a join would and be more performant.&lt;/P&gt;

&lt;P&gt;I edited the answer so it only returns results where those two fields match.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 16:54:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497487#M138559</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2019-12-05T16:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497488#M138560</link>
      <description>&lt;P&gt;Thanks to both of you for the prompt reply.&lt;/P&gt;

&lt;P&gt;I used the Dustin's suggestion because is more clear for my  little knowledge, later will try the "selfjoin" also.&lt;BR /&gt;
To filter the columns I used table command  as last row&lt;/P&gt;

&lt;P&gt;(sourcetype="Sourcetype_A" s1_field4="Completed") OR sourcetype="Sourcetype_B" &lt;BR /&gt;
 | eval joiner=if(sourcetype="Sourcetype_A", s1_field2, s2_field1)&lt;BR /&gt;
 | stats values(*) as * by joiner&lt;BR /&gt;
 | table s1_field2, s1_field1,s2_field2,s2_field3&lt;/P&gt;

&lt;P&gt;is it a good way to shows the fields ?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:12:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497488#M138560</guid>
      <dc:creator>gballanti</dc:creator>
      <dc:date>2020-09-30T03:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497489#M138561</link>
      <description>&lt;P&gt;just an update ...&lt;BR /&gt;
the following query &lt;/P&gt;

&lt;P&gt;(sourcetype="snow:task_sla" dv_has_breached=false dv_stage=Completed dv_sla="FW-Guasto non bloccante fuori sede no A-SLA21") OR sourcetype="snow:incident" | eval joiner=if(sourcetype="snow:task_sla", dv_task, dv_number) | stats values(dv_task) as dv_task values(dv_number) as dv_number values(dv_sla) as dv_sla by joiner&lt;/P&gt;

&lt;P&gt;return an unexpected behavior&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/277733-snow-sla.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;I have to get only the highlighted rows, where dv_task and dv_number matches.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:16:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497489#M138561</guid>
      <dc:creator>gballanti</dc:creator>
      <dc:date>2020-09-30T03:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497490#M138562</link>
      <description>&lt;P&gt;probably my previous comment is gone ... I wanted to thank you for the answers&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 12:54:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497490#M138562</guid>
      <dc:creator>gballanti</dc:creator>
      <dc:date>2019-12-06T12:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497491#M138563</link>
      <description>&lt;P&gt;Yep, this is an easy fix.  Modify your query by adding a filter at the end to only include when they match:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(sourcetype="snow:task_sla" dv_has_breached=false dv_stage=Completed dv_sla="FW-Guasto non bloccante fuori sede no A-SLA21") OR sourcetype="snow:incident" 
| eval joiner=if(sourcetype="snow:task_sla", dv_task, dv_number) 
| stats values(dv_task) as dv_task values(dv_number) as dv_number values(dv_sla) as dv_sla by joiner
| where dv_task=dv_number
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2019 13:31:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497491#M138563</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2019-12-06T13:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497492#M138564</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;(sourcetype="snow:task_sla" dv_has_breached=false dv_stage=Completed dv_sla="FW-Guasto non bloccante fuori sede no A-SLA21") OR sourcetype="snow:incident" 
| eval joiner=if(sourcetype="snow:task_sla", dv_task, dv_number) 
| stats values(dv_task) as dv_task values(dv_number) as dv_number values(dv_sla) as dv_sla by joiner
| where dv_task==dv_number
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ask, and it shall be given you.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 13:35:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497492#M138564</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-06T13:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497493#M138565</link>
      <description>&lt;P&gt;thanks to everyone , the solution proposed works as expected.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 14:00:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/497493#M138565</guid>
      <dc:creator>gballanti</dc:creator>
      <dc:date>2019-12-06T14:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/552758#M156906</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I tried in same way, but not working&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;index=my_index type=outer OR type=inner&lt;BR /&gt;|rename msg.* AS *&lt;BR /&gt;| eval joiner=if(type=outer, _id, source_id)&lt;BR /&gt;| stats values(*) as * by joiner&lt;BR /&gt;| where ticket_num=TicketNum&lt;/P&gt;&lt;P&gt;|table event_id, serial_id&lt;BR /&gt;&lt;BR /&gt;Can you please help me here&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/215385"&gt;@dmarling&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 11:29:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/552758#M156906</guid>
      <dc:creator>Anji02</dc:creator>
      <dc:date>2021-05-24T11:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/552780#M156909</link>
      <description>&lt;P&gt;The joiner eval doesn't have double quotes around "outer" so it's trying to say when the value in field type equals the value in field outer, then use the value in field _id.&amp;nbsp; What you want to do is wrap outer with double quotes so the eval command knows you are looking for the field type to have a value of "outer."&lt;/P&gt;&lt;LI-CODE lang="python"&gt;index=my_index (type=outer OR type=inner)
| rename msg.* AS *
| eval joiner=if(type="outer", _id, source_id)
| stats values(*) as * by joiner
| where ticket_num=TicketNum&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 24 May 2021 13:22:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/552780#M156909</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2021-05-24T13:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/691965#M235566</link>
      <description>&lt;P class="lia-align-left"&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/215385"&gt;@dmarling&lt;/a&gt;&amp;nbsp;&amp;nbsp; pretty good explanation ! .&amp;nbsp;&lt;BR /&gt;But now I need to go one step further . Based on result of stats commands I want to create timechart.&amp;nbsp;&amp;nbsp; First I tried to replace stats with timechart but it simply does not work.&amp;nbsp; Then I created table from stats result and base on this table wanted to create a time chart. But I rather feel than know&amp;nbsp; it is not a good way.&amp;nbsp; Would you give any example how to do it please. Even based on this simple from source post&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 17:53:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/691965#M235566</guid>
      <dc:creator>kp_pl</dc:creator>
      <dc:date>2024-06-28T17:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/691968#M235567</link>
      <description>&lt;P&gt;You just need the _time field that isn't multivalued to be present for timechart to work.&amp;nbsp; Assuming you are working with the example you replied to you would simply add "| eval _time=min(_time) | timechart count" after the where line.&amp;nbsp; The eval is ensuring you take the earliest time if it is multi-valued.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 18:02:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/691968#M235567</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2024-06-28T18:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two searches with common value into one table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/691994#M235575</link>
      <description>&lt;P&gt;something is not clear because it does not return any rows now:&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;(...)&lt;/EM&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| stats values(*) as * by joiner | where ctx_ecid=ecid_d
| eval _time=min(_time) | timechart span=5min avg(time_taken)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;without the last line with timechart it returns all expected rows, with it - none &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and one more question . Right now I do &lt;EM&gt;stats(*) as * by joiner&lt;/EM&gt;&amp;nbsp; but this returns all fields from both indexes. I suppose it cost a lot to transfer such big amount of data especially each my index has 10-20 fields and thousands records. In fact I use only 2-3 fields from each index so I tried to something like :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| stats values(field1) as field1, values(field2) as field2, values(field3) as field3 by joiner (...)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;but it does not return rows &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&amp;nbsp; Why ?&amp;nbsp;&amp;nbsp; how&amp;nbsp; to modify it to returns only fields I need?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jun 2024 08:06:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-two-searches-with-common-value-into-one-table/m-p/691994#M235575</guid>
      <dc:creator>kp_pl</dc:creator>
      <dc:date>2024-06-29T08:06:51Z</dc:date>
    </item>
  </channel>
</rss>

