<?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 join two tables with default row if tables do not match? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-tables-with-default-row-if-tables-do-not-match/m-p/151931#M42554</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;i have a table whose result is as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;parameter value result
P1          V1    R1
P2          V2    R2
P3          V3    R3
P4          V4    R4
P5          V5    R5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And a lookup file as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;parameter value result color1 color2
P1          V1    R1     C1     C2
def        def   def     C3     C4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I join the two table? If the parameter value result doesn't match for both, then it should take the "def" row value.&lt;/P&gt;

&lt;P&gt;Planning to get the result as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;parameter value result color1 color2
P1          V1    R1     C1     C2
P2          V2    R2     C3     C4
P3          V3    R3     C3     C4
P4          V4    R4     C3     C4
P5          V5    R5     C3     C4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have used the join , but doesnt displays the result as I expected.&lt;BR /&gt;
Please Help...!!&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jun 2015 14:41:50 GMT</pubDate>
    <dc:creator>harshal_chakran</dc:creator>
    <dc:date>2015-06-09T14:41:50Z</dc:date>
    <item>
      <title>How to join two tables with default row if tables do not match?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-tables-with-default-row-if-tables-do-not-match/m-p/151931#M42554</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;i have a table whose result is as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;parameter value result
P1          V1    R1
P2          V2    R2
P3          V3    R3
P4          V4    R4
P5          V5    R5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And a lookup file as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;parameter value result color1 color2
P1          V1    R1     C1     C2
def        def   def     C3     C4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I join the two table? If the parameter value result doesn't match for both, then it should take the "def" row value.&lt;/P&gt;

&lt;P&gt;Planning to get the result as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;parameter value result color1 color2
P1          V1    R1     C1     C2
P2          V2    R2     C3     C4
P3          V3    R3     C3     C4
P4          V4    R4     C3     C4
P5          V5    R5     C3     C4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have used the join , but doesnt displays the result as I expected.&lt;BR /&gt;
Please Help...!!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2015 14:41:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-tables-with-default-row-if-tables-do-not-match/m-p/151931#M42554</guid>
      <dc:creator>harshal_chakran</dc:creator>
      <dc:date>2015-06-09T14:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to join two tables with default row if tables do not match?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-tables-with-default-row-if-tables-do-not-match/m-p/151932#M42555</link>
      <description>&lt;P&gt;This will do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... lookup &amp;lt;yourLookupName&amp;gt; parameter value result OUTPUT color1 AS color1lookup color2 AS color2lookup | eval color1=coalesce(color1lookup,"C3") | eval color2=coalesce(color2lookup,"C4")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jun 2015 17:32:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-tables-with-default-row-if-tables-do-not-match/m-p/151932#M42555</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-06-09T17:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to join two tables with default row if tables do not match?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-tables-with-default-row-if-tables-do-not-match/m-p/151933#M42556</link>
      <description>&lt;P&gt;Let's say your lookup is named "myLookup", then here's what you want.   The rows that are a match for all three values, (parameter, value and result) will get the corresponding color1 and color2 values from the lookup.   The rows that are not a match will end up with whatever color1 and color2 values are listed in the row that has the value "def" for all three fields.    &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search terms&amp;gt; | lookup myLookup parameter value result OUTPUT color1 color2 |fillnull defaultParameter defaultValue defaultResult value="def" | lookup myLookup parameter as defaultParameter value as defaultValue result as defaultResult OUTPUT defaultColor1 defaultColor2 | eval color1=coalesce(color1,defaultColor1) | eval color2=coalesce(color2,defaultColor2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I don't normally advise using append or join,  but in cases where the subsearch is extremely efficient and returns only a couple rows,  their drawbacks don't really come into play. &lt;/P&gt;

&lt;P&gt;Since the above example runs the lookup twice, and with a join command all you're joining in is an inputlookup search yielding only a single row,  the join command way below is a viable alternative. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search terms&amp;gt; | lookup myLookup parameter value result OUTPUT color1 color2 | eval foo=1 | join foo [| inputlookup myLookup | search parameter="def" value="def" result="def" | rename color1 as defaultColor1 defaultColor2 | eval foo=1 | table foo defaultColor1 defaultColor2] | fields - foo | eval color1=coalesce(color1,defaultColor1) | eval color2=coalesce(color2,defaultColor2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or instead of the eval+coalesce at the end you can avail yourself of the join command's &lt;CODE&gt;overwrite&lt;/CODE&gt; argument. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search terms&amp;gt; | lookup myLookup parameter value result OUTPUT color1 color2 | eval foo=1 | join overwrite=f foo [| inputlookup myLookup | search parameter="def" value="def" result="def" | eval foo=1 | table foo color1 color2] | fields - foo 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jun 2015 19:49:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-two-tables-with-default-row-if-tables-do-not-match/m-p/151933#M42556</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2015-06-09T19:49:16Z</dc:date>
    </item>
  </channel>
</rss>

