<?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: How to use append and join in same search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336654#M99884</link>
    <description>&lt;P&gt;How is this search sentence?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(Search q)
|join StIP EnIP  type=outer [search (Search r)|eval flg=1]
|stats sum(total) as all_total,sum(eval(if(flg=1,total,0))) as r_total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;※Please be careful when increasing the number of sub search because there is a limit of 10000 defaults.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Oct 2017 13:36:54 GMT</pubDate>
    <dc:creator>HiroshiSatoh</dc:creator>
    <dc:date>2017-10-27T13:36:54Z</dc:date>
    <item>
      <title>How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336653#M99883</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;

&lt;P&gt;I need to use both append and join in same commmand .Please help me to change the below sql to splunk search &lt;/P&gt;

&lt;P&gt;SELECT sum(q.total)&lt;BR /&gt;
FROM [SE_COMP].[Q] q -- need in first row&lt;/P&gt;

&lt;P&gt;SELECT sum(q.total)&lt;BR /&gt;
FROM [SE_COMP].[Q] q&lt;BR /&gt;
INNER JOIN  [SE_COMP].[R] r ON q.StIP = r.StIP AND q.EnIP = r.EnIP -- need in second row after stats at the end of search.&lt;/P&gt;

&lt;P&gt;I am in need of two rows values with ,&lt;/P&gt;

&lt;P&gt;sum(q.total)  in first row and &lt;BR /&gt;
combined values in second search in second row after stats.&lt;/P&gt;

&lt;P&gt;Please hep in framing the search .&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:30:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336653#M99883</guid>
      <dc:creator>umsundar2015</dc:creator>
      <dc:date>2020-09-29T16:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336654#M99884</link>
      <description>&lt;P&gt;How is this search sentence?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(Search q)
|join StIP EnIP  type=outer [search (Search r)|eval flg=1]
|stats sum(total) as all_total,sum(eval(if(flg=1,total,0))) as r_total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;※Please be careful when increasing the number of sub search because there is a limit of 10000 defaults.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 13:36:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336654#M99884</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2017-10-27T13:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336655#M99885</link>
      <description>&lt;P&gt;Hi Hiroshi,&lt;/P&gt;

&lt;P&gt;Thank you for your search.&lt;/P&gt;

&lt;P&gt;I am getting no results in this .Can you please help me with some other search &lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 14:13:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336655#M99885</guid>
      <dc:creator>umsundar2015</dc:creator>
      <dc:date>2017-10-27T14:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336656#M99886</link>
      <description>&lt;P&gt;So, first, go read this so you understand how to think about SPL, as opposed to SQL.  A direct translation is almost always inefficient.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/561130/sql-analogy-for-my-log-search-join-two-tables-wher.html" target="_blank"&gt;https://answers.splunk.com/answers/561130/sql-analogy-for-my-log-search-join-two-tables-wher.html&lt;/A&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Second, you need to turn your SQL specifications into plain English&lt;/P&gt;

&lt;P&gt;1) There is a table called Q in SE_Comp&lt;BR /&gt;
2) I want the sum of the field "Total" from all of Q&lt;BR /&gt;
3) There is also a table called R in SE_COMP&lt;BR /&gt;
4) I want the sum of the field "Total" from Q, but only when the StIP and EnIP from Q match a record in R.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Third, code the SPL to achieve the English result.&lt;/P&gt;

&lt;P&gt;There are at least 5 ways to code this one, depending on the characteristics of the underlying data.&lt;/P&gt;

&lt;P&gt;Here's one....&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; (your search that gets all Q) OR (your search that gets all R)
| eval FoundR=case(test to see if it is a record from R, 1.00)
| eval QTotal=case(test to see if it is a record from Q, Total from Q)
| eventstats max(FoundR) as FoundR by StIP EnIP
| eval  RTotal=FoundR*QTotal
| stats sum(QTotal) as QTotal sum(RTotal) as RTotal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some of the details may be unneeded. For example, if there is a field &lt;CODE&gt;total&lt;/CODE&gt; on the Q records and no field by that name on the R records, then the &lt;CODE&gt;eval QTotal=&lt;/CODE&gt; line is unneeded.  If there is any field that always appears on R that never appears on Q, then field that can be used instead of &lt;CODE&gt;FoundR&lt;/CODE&gt;, and so on. &lt;/P&gt;

&lt;P&gt;The above general method is always preferred to the join.  &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Here's another method...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; (your search that gets all Q) 
 | join type=left StIP EnIP [ your search that gets all R | table StIP EnIP | eval FoundR=1.00] 
 | stats sum(Total from Q) as QTotal sum(eval(FoundR*Total From Q)) as RTotal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This second method is equivalent to the one posted by &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/100698"&gt;@HiroshiSatoh&lt;/a&gt;.  I use a couple of different tricks, but the performance should be similar.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;This third method can be used when the R records are fairly static, so they can be made into a lookup table.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  (your search that gets all Q) 
 | lookup MyRLookupName StIP EnIP OUTPUT anyfieldinlookupsuchasStIP as FoundR 
 | stats sum(Total from Q) as QTotal sum(eval(case(isnotnull(FoundR),Total From Q))) as RTotal
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:26:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336656#M99886</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-09-29T16:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336657#M99887</link>
      <description>&lt;P&gt;Does StIP and EnIP exist in both Q and R search results?&lt;/P&gt;

&lt;P&gt;Please show me the search sentences you are running.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 23:41:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336657#M99887</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2017-10-27T23:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336658#M99888</link>
      <description>&lt;P&gt;index=q|fillnull|join StIP EnIP type=outer [search index=R|fillnull|eval flag=1]&lt;BR /&gt;
|stats sum(Total) as all_total,sum(eval(if(flag=1,Total,0))) as r_total&lt;/P&gt;

&lt;P&gt;Its working , but i am finding difference of 90k les  when comparing to sql query with splunk search&lt;/P&gt;

&lt;P&gt;Can you please help to equate the counts &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:26:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336658#M99888</guid>
      <dc:creator>umsundar2015</dc:creator>
      <dc:date>2020-09-29T16:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336659#M99889</link>
      <description>&lt;P&gt;If there are more than 10,000 sub search results, you need to set limits.conf.&lt;BR /&gt;
As DalJeanis explains, looking up JOIN is better. Please try lookup.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 11:01:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336659#M99889</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2017-10-30T11:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336660#M99890</link>
      <description>&lt;P&gt;ok. But we should not use lookup Hiroshi.&lt;/P&gt;

&lt;P&gt;so i need to done this in this search itself.Using join also i am getting the same difference .&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 11:05:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336660#M99890</guid>
      <dc:creator>umsundar2015</dc:creator>
      <dc:date>2017-10-30T11:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336661#M99891</link>
      <description>&lt;P&gt;↓There are no more than 10 thousand items and no duplication exists&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index=R|stats count by StIP,EnIP
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If it is over 10,000&lt;BR /&gt;
set limit in limits.conf for subsearch&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.1/Admin/Limitsconf"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.1/Admin/Limitsconf&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;↓Is this result correct?&lt;BR /&gt;
    index=q|join StIP EnIP type=outer [search index=R]&lt;BR /&gt;
    |stats sum(Total)  as r_total&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 11:42:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336661#M99891</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2017-10-30T11:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to use append and join in same search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336662#M99892</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;

&lt;P&gt;How to bring the same two rows as mentioned above with only one index with Total_ip field ??&lt;/P&gt;

&lt;P&gt;can u pls help me &lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 07:51:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-append-and-join-in-same-search/m-p/336662#M99892</guid>
      <dc:creator>umsundar2015</dc:creator>
      <dc:date>2017-10-31T07:51:58Z</dc:date>
    </item>
  </channel>
</rss>

