<?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: Join two search results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104416#M27057</link>
    <description>&lt;P&gt;I would try to do this without a join if possible.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="A" OR sourcetype="B" 
| stats last(processed_timestamp) as start first(processed_timestamp) as end by project sourcetype 
| eval phaseI_start=case(sourcetype=="A", start) 
| eval phaseI_end=case(sourcetype=="A", end) 
| eval phaseII_start=case(sourcetype=="B", start) 
| eval phaseII_end=case(sourcetype=="B", end) 
| stats first(phaseI_start) as phaseI_start first(phaseI_end) as phaseI_end first(phaseII_start) as phaseII_start first(phaseII_end) as phaseII_end by project
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Okay, thats a lot of pipes.  what the heck is going on?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="A" OR sourcetype="B"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;gets all our events.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| stats last(processed_timestamp) as start first(processed_timestamp) as end by project sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;gives us a table of the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;project | sourcetype | start                   | end
p1        A            5/12/13  2:10:45.344 PM   5/13/13  2:10:45.344 PM
p1        B            6/12/13  2:10:45.344 PM   6/13/13 12:11:45.344 PM
etc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now lets get those values into the desired fields for our results.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| eval phaseI_start=case(sourcetype=="A", start)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This says create a field called phaseI_start and when the sourcetype=="A" fill it with the start value, otherwise it's null.  Repeat for each field.  Now we have our phaseI_start, phaseI_end, etc fields populated.  All that's left is to get them into tabular format.  Stats can do this too.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| stats first(phaseI_start) as phaseI_start first(phaseI_end) as phaseI_end first(phaseII_start) as phaseII_start first(phaseII_end) as phaseII_end by project
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Notes on the first() last() stuff.  First() refers to the first value seen in the search.  Since searches run from the most recent and go back in time, the first() value seen is the most recent value, in this case our end timestamps.  conversely, last() refers to the last value seen, which is the oldest value, and would refer to our start timestamps.&lt;/P&gt;

&lt;P&gt;End result is what you're looking for without expensive joins or transactions!&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jul 2013 21:52:31 GMT</pubDate>
    <dc:creator>emiller42</dc:creator>
    <dc:date>2013-07-23T21:52:31Z</dc:date>
    <item>
      <title>Join two search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104414#M27055</link>
      <description>&lt;P&gt;I am trying to join two search results with the common field project. &lt;/P&gt;

&lt;P&gt;Here is an example:&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;First result would return for Phase-I&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;
project      sub-project         processed_timestamp
p1              sp11            5/12/13  2:10:45.344 PM
p1              sp12            5/13/13 12:11:45.344 PM
p1              sp13            5/13/13  2:10:45.344 PM

p2              sp21            6/23/13 12:10:45.344 PM
p2              sp22            6/24/13 12:10:45.344 PM

p3              sp31            7/23/13 12:10:45.344 PM
p3              sp32            7/24/13 12:10:45.344 PM

p4              sp41            7/23/13 12:10:45.344 PM
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Second result would return for Phase-II&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;
project      sub-project         processed_timestamp&lt;BR /&gt;
p1              sp11            6/12/13  2:10:45.344 PM&lt;BR /&gt;
p1              sp12            6/13/13 12:11:45.344 PM&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;p2              sp21            7/23/13 12:10:45.344 PM&lt;BR /&gt;
p2              sp22            7/24/13 12:10:45.344 PM&lt;BR /&gt;
&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Here is the output I am looking for&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;


project         phaseI_start                    phaseI_end              phaseII_start                   phaseII_end
p1      5/12/13  2:10:45.344 PM     5/13/13  2:10:45.344 PM     6/12/13  2:10:45.344 PM     6/13/13 12:11:45.344 PM
p2      6/23/13 12:10:45.344 PM     6/24/13 12:10:45.344 PM     7/23/13 12:10:45.344 PM     7/24/13 12:10:45.344 PM
p3      7/23/13 12:10:45.344 PM     7/24/13 12:10:45.344 PM
p4      7/23/13 12:10:45.344 PM     7/23/13 12:10:45.344 PM (has only one sub project so sametime applies to start and end)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;I tried using transaction for each searches separately and used join as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;
sourcetype="A"| transaction project |eval phaseI_start= ...|eval phaseI_end = .....| fields project, phaseI_start, phaseI_end| join project [search sourcetype="B"| transaction project |eval phaseII_start= ...|eval phaseII_end = .....| fields project, phaseII_start, phaseII_end]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I donot get any result back. However if I apply filter to get specific projects using "where like (project,"P1%") in both searches then it works. First search would return more than 10000 records and second would return about 5000.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Sanjay&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2013 20:19:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104414#M27055</guid>
      <dc:creator>sanjay_shrestha</dc:creator>
      <dc:date>2013-07-23T20:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Join two search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104415#M27056</link>
      <description>&lt;P&gt;I was able to get the result using STATS. I had to rename field to processed_timestamp2 for phase II result. Also used eval to format date as follow.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;

sourcetype="A" OR sourcetype="B"| STATS min(processed_timestamp1), max(processed_timestamp1),min(processed_timestamp2), max(processed_timestamp2) by project |eval phaseI_start= ...|eval phaseI_end = .... |eval phaseII_start= ...|eval phaseII_end = .....| table project, phaseI_start, phaseI_end, phaseII_start, phaseII_end

&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Cheers!!!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2013 21:47:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104415#M27056</guid>
      <dc:creator>sanjay_shrestha</dc:creator>
      <dc:date>2013-07-23T21:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Join two search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104416#M27057</link>
      <description>&lt;P&gt;I would try to do this without a join if possible.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="A" OR sourcetype="B" 
| stats last(processed_timestamp) as start first(processed_timestamp) as end by project sourcetype 
| eval phaseI_start=case(sourcetype=="A", start) 
| eval phaseI_end=case(sourcetype=="A", end) 
| eval phaseII_start=case(sourcetype=="B", start) 
| eval phaseII_end=case(sourcetype=="B", end) 
| stats first(phaseI_start) as phaseI_start first(phaseI_end) as phaseI_end first(phaseII_start) as phaseII_start first(phaseII_end) as phaseII_end by project
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Okay, thats a lot of pipes.  what the heck is going on?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="A" OR sourcetype="B"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;gets all our events.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| stats last(processed_timestamp) as start first(processed_timestamp) as end by project sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;gives us a table of the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;project | sourcetype | start                   | end
p1        A            5/12/13  2:10:45.344 PM   5/13/13  2:10:45.344 PM
p1        B            6/12/13  2:10:45.344 PM   6/13/13 12:11:45.344 PM
etc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now lets get those values into the desired fields for our results.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| eval phaseI_start=case(sourcetype=="A", start)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This says create a field called phaseI_start and when the sourcetype=="A" fill it with the start value, otherwise it's null.  Repeat for each field.  Now we have our phaseI_start, phaseI_end, etc fields populated.  All that's left is to get them into tabular format.  Stats can do this too.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| stats first(phaseI_start) as phaseI_start first(phaseI_end) as phaseI_end first(phaseII_start) as phaseII_start first(phaseII_end) as phaseII_end by project
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Notes on the first() last() stuff.  First() refers to the first value seen in the search.  Since searches run from the most recent and go back in time, the first() value seen is the most recent value, in this case our end timestamps.  conversely, last() refers to the last value seen, which is the oldest value, and would refer to our start timestamps.&lt;/P&gt;

&lt;P&gt;End result is what you're looking for without expensive joins or transactions!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2013 21:52:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104416#M27057</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2013-07-23T21:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Join two search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104417#M27058</link>
      <description>&lt;P&gt;Thanks for your an elegant solution. This way I do not need to rename the field.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2013 13:23:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104417#M27058</guid>
      <dc:creator>sanjay_shrestha</dc:creator>
      <dc:date>2013-07-24T13:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Join two search results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104418#M27059</link>
      <description>&lt;P&gt;What would be best approach if these two searches results should joined by project? That means the output would be only from project p1 and p2.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;
project         phaseI_start                    phaseI_end              phaseII_start                   phaseII_end
p1      5/12/13  2:10:45.344 PM     5/13/13  2:10:45.344 PM     6/12/13  2:10:45.344 PM     6/13/13 12:11:45.344 PM
p2      6/23/13 12:10:45.344 PM     6/24/13 12:10:45.344 PM     7/23/13 12:10:45.344 PM     7/24/13 12:10:45.344 PM
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jul 2013 20:18:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-two-search-results/m-p/104418#M27059</guid>
      <dc:creator>sanjay_shrestha</dc:creator>
      <dc:date>2013-07-31T20:18:21Z</dc:date>
    </item>
  </channel>
</rss>

