<?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: Splunk left join not returning as expected in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668779#M229406</link>
    <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;I managed to not use the join command, the above feedback helped.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I decided to go with Union this seems to be working, what do you think?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=customer ((name IN (gate-green, gate-blue) msg="*First time: *")
| rex field=msg "First time: (?&amp;lt;UserId&amp;gt;\d+)"
| eval FirtRequest = 1
|union
[ search index name IN (cust-blue, cust-green) msg="*COMPLETED *")
   | rex field=msg "Message\|[^\t\{]*(?&amp;lt;json&amp;gt;{[^\t]+})"
   | spath input=json path=infoId output=UserId
   | eval Completed = 1]
| stats max(FirstRequest) AS FirstRequest max(Completed) BY UserId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Nov 2023 18:19:46 GMT</pubDate>
    <dc:creator>MrJohn230</dc:creator>
    <dc:date>2023-11-15T18:19:46Z</dc:date>
    <item>
      <title>Splunk left join not returning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668742#M229395</link>
      <description>&lt;P&gt;I have the below code. I know that values exist under the subsearch which are not returning when I run the below query. However, when I uncomment the "where clause" in the sub search the values appear. I don't know what I have done incorrectly for my results to not show. I've also commented out the |search and it still doesn't show that these values exist in the subsearch.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=customer name IN (gate-green, gate-blue) msg="*First time: *"
    | rex field=msg "First time: (?&amp;lt;UserId&amp;gt;\d+)"
    | eval FirstRequest = 1
    | join type=left UserId
     [search index=customer name IN (cust-blue, cust-green) msg="*COMPLETED *"
       | rex field=msg "Message\|[^\t\{]*(?&amp;lt;json&amp;gt;{[^\t]+})"
       | spath input=json path=infoId output=UserId
       | eval Completed = 1
       ```| where UserId IN (125,999,418,208)```]
| table UserId, Completed
| search UserId IN (125,999,418,208)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 14:16:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668742#M229395</guid>
      <dc:creator>MrJohn230</dc:creator>
      <dc:date>2023-11-15T14:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk left join not returning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668746#M229398</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/261678"&gt;@MrJohn230&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;at first, if possible try to avoid to use join command!&lt;/P&gt;&lt;P&gt;I understand that all of us arrive from SQL, but Splunk isn't a database so join command should be avoided all the times it's possible and replaced e.g. with the stats command, because it's a very slow and resource eater command.&lt;/P&gt;&lt;P&gt;e.g. try something like this (obviously I cannot check it):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=customer ((name IN (gate-green, gate-blue) msg="*First time: *") OR name IN (cust-blue, cust-green) msg="*COMPLETED *")
| rex field=msg "First time: (?&amp;lt;UserId&amp;gt;\d+)"
| rex field=msg "Message\|[^\t\{]*(?&amp;lt;json&amp;gt;{[^\t]+})"
| spath input=json path=infoId output=UserId
| eval status=if(name IN (gate-green, gate-blue) AND msg="*First time: *","FirstRequest","Completed")
| stats dc(status) AS status_count values(status) AS status BY UserId
| eval status=if(status_count=2,"both",status)
| table UserId status
| search UserId IN (125,999,418,208)&lt;/LI-CODE&gt;&lt;P&gt;Then you can define if to maintain all the UserIds or only the ones with both the statuses.&lt;/P&gt;&lt;P&gt;About your search, try to use quotes in the IN values.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 14:44:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668746#M229398</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-11-15T14:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk left join not returning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668779#M229406</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;I managed to not use the join command, the above feedback helped.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I decided to go with Union this seems to be working, what do you think?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=customer ((name IN (gate-green, gate-blue) msg="*First time: *")
| rex field=msg "First time: (?&amp;lt;UserId&amp;gt;\d+)"
| eval FirtRequest = 1
|union
[ search index name IN (cust-blue, cust-green) msg="*COMPLETED *")
   | rex field=msg "Message\|[^\t\{]*(?&amp;lt;json&amp;gt;{[^\t]+})"
   | spath input=json path=infoId output=UserId
   | eval Completed = 1]
| stats max(FirstRequest) AS FirstRequest max(Completed) BY UserId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2023 18:19:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668779#M229406</guid>
      <dc:creator>MrJohn230</dc:creator>
      <dc:date>2023-11-15T18:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk left join not returning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668793#M229409</link>
      <description>&lt;P&gt;Your where clause is wrong - it does not support the IN construct, like search. You could do it with&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where in(UserId,125,999,418,208)&lt;/LI-CODE&gt;&lt;P&gt;or using search IN. As&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;says, using join and subsearches is not a good habit, using stats can normall do the same and does not have limitations that join/subsearch has, e.g. this is an example of using stats.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=customer (name IN (gate-green, gate-blue) msg="*First time: *") OR (name IN (cust-blue, cust-green) msg="*COMPLETED *")
| rex field=msg "First time: (?&amp;lt;UserId&amp;gt;\d+)"
| eval FirstRequest = if(isnotnull(UserId),1,null())
| rex field=msg "Message\|[^\t\{]*(?&amp;lt;json&amp;gt;{[^\t]+})"
| spath input=json path=infoId output=CompletedUserId
| eval Completed = if(isnotnull(CompletedUserId), 1, null())
| eval UserId=coalesce(UserId, CompletedUserId)
| stats values(Completed) as Completed by UserId
| search UserId IN (125,999,418,208)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 15 Nov 2023 21:59:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668793#M229409</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-11-15T21:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk left join not returning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668818#M229415</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/261678"&gt;@MrJohn230&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I continue to prefer the solution I hinted because union is very similar to join and maintain the ame limit of 50,000 results like all the subsearches.&lt;/P&gt;&lt;P&gt;If it solves your requirement, use it, but I hint to tale practice using stats that's better and faster.&lt;/P&gt;&lt;P&gt;did you solved the initial issue of the eval?&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 07:41:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668818#M229415</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-11-16T07:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk left join not returning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668824#M229418</link>
      <description>&lt;P&gt;One more vote to not to use join or union. It usually have more issues than it solves.&lt;/P&gt;&lt;P&gt;Here is one old post how to replace join with stats with different join types&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/What-is-the-relation-between-the-Splunk-inner-left-join-and-the/m-p/391288/thread-id/113948" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/What-is-the-relation-between-the-Splunk-inner-left-join-and-the/m-p/391288/thread-id/113948&lt;/A&gt;&lt;/P&gt;&lt;P&gt;There are also many .conf presentations why you should use stats instead of join like&amp;nbsp;&lt;A href="https://conf.splunk.com/watch/conf-online.html?search=join%20without%20join#/" target="_blank"&gt;https://conf.splunk.com/watch/conf-online.html?search=join%20without%20join#/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 08:00:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668824#M229418</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2023-11-16T08:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk left join not returning as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668839#M229421</link>
      <description>&lt;P&gt;One additional remark about your searches (both the outer one and the subsearch) - don't use wildcards at the beginning of your search term if you can avoid it.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 10:22:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-left-join-not-returning-as-expected/m-p/668839#M229421</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-11-16T10:22:08Z</dc:date>
    </item>
  </channel>
</rss>

