<?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: Help me with join query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290980#M87924</link>
    <description>&lt;P&gt;I always try to avoid commands that use subsearches since they don't scale.&lt;/P&gt;

&lt;P&gt;You should be able to get the job done with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=ABC (sourcetype=xyz OR sourcetype=pqr)
 | eval joinid=coalesce(XID,MyID)
 | stats count(XID) AS Count, values(Name) AS Name by joinid
 | rename joinid AS MyID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This takes some extra steps for clarity, but the gist is that you are using the "by" field in the stats to perform the "join". The count will be constrained to only events with an XID field, meaning that your &lt;CODE&gt;sourcetype=pqr&lt;/CODE&gt; events won't influence your count, even though they are in the resultset.&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2017 18:50:31 GMT</pubDate>
    <dc:creator>jacobwilkins</dc:creator>
    <dc:date>2017-05-12T18:50:31Z</dc:date>
    <item>
      <title>Help me with join query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290976#M87920</link>
      <description>&lt;P&gt;index=ABC sourcetype=xyz | stats count by XID| table XID count&lt;/P&gt;

&lt;P&gt;XID Count&lt;BR /&gt;
101     2&lt;BR /&gt;
102     3&lt;BR /&gt;
103     4&lt;/P&gt;

&lt;P&gt;index=ABC sourcetype=pqr |  table MyID Name&lt;/P&gt;

&lt;P&gt;MyID Name&lt;BR /&gt;
101    jhgkjmhgku&lt;BR /&gt;
102    jhkfythhgkk&lt;BR /&gt;
103    kiugikyukhy&lt;/P&gt;

&lt;P&gt;How to join this to get result.&lt;/P&gt;

&lt;P&gt;MyID Name                count&lt;BR /&gt;
101    jhgkjmhgku        2&lt;BR /&gt;
102    jhkfythhgkk        3&lt;BR /&gt;
103    kiugikyukhy        4&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 17:33:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290976#M87920</guid>
      <dc:creator>sravankaripe</dc:creator>
      <dc:date>2017-05-12T17:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with join query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290977#M87921</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=ABC sourcetype=xyz | stats count by XID | rename XID as MyID
| join MyID [index=ABC sourcetype=pqr | table MyID Name]
| table MyID Name count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 May 2017 17:46:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290977#M87921</guid>
      <dc:creator>ckunath</dc:creator>
      <dc:date>2017-05-12T17:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with join query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290978#M87922</link>
      <description>&lt;P&gt;try this&lt;/P&gt;

&lt;P&gt;index=ABC sourcetype=xyz | stats count by XID | appendcols  [search index=ABC sourcetype=pqr  | table MyID Name] | table MyID Name count&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 17:58:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290978#M87922</guid>
      <dc:creator>SplunkersRock</dc:creator>
      <dc:date>2017-05-12T17:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with join query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290979#M87923</link>
      <description>&lt;P&gt;Yup.  Or,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=ABC sourcetype=xyz OR sourcetype=pqr 
| eval MyID = coalesce(MyID,XID)
| stats count(eval(sourcetype=xyz)) as count, values(Name) as Name by MyID 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 May 2017 18:00:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290979#M87923</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-12T18:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with join query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290980#M87924</link>
      <description>&lt;P&gt;I always try to avoid commands that use subsearches since they don't scale.&lt;/P&gt;

&lt;P&gt;You should be able to get the job done with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=ABC (sourcetype=xyz OR sourcetype=pqr)
 | eval joinid=coalesce(XID,MyID)
 | stats count(XID) AS Count, values(Name) AS Name by joinid
 | rename joinid AS MyID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This takes some extra steps for clarity, but the gist is that you are using the "by" field in the stats to perform the "join". The count will be constrained to only events with an XID field, meaning that your &lt;CODE&gt;sourcetype=pqr&lt;/CODE&gt; events won't influence your count, even though they are in the resultset.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 18:50:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-me-with-join-query/m-p/290980#M87924</guid>
      <dc:creator>jacobwilkins</dc:creator>
      <dc:date>2017-05-12T18:50:31Z</dc:date>
    </item>
  </channel>
</rss>

