<?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 do I write this SQL query as a join search in Splunk? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-this-SQL-query-as-a-join-search-in-Splunk/m-p/211356#M61819</link>
    <description>&lt;P&gt;I will ask my question using online forum as an example.  &lt;/P&gt;

&lt;P&gt;It has Event Log that tracks all user actions from login to logout. Contains the following significant fields: &lt;CODE&gt;EventTime&lt;/CODE&gt;, &lt;CODE&gt;UserID&lt;/CODE&gt;, &lt;CODE&gt;IP address&lt;/CODE&gt;,  &lt;CODE&gt;Action&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;We want to write a search that identifies users that were banned ( &lt;CODE&gt;Action='Ban'&lt;/CODE&gt; ) and then quickly came back under another &lt;CODE&gt;UserID&lt;/CODE&gt;, but still with the same &lt;CODE&gt;IP&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;In SQL I would use the following &lt;CODE&gt;SELF JOIN&lt;/CODE&gt; (assuming &lt;CODE&gt;TimeDiff&lt;/CODE&gt; is a valid function returning seconds): &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SELECT ev1.IP,  ev1.UserID, ev1.EventTime, ev2.UserID, ev2.EventTime, ev2.Action
FROM EventLog ev1
JOIN Eventlog ev2 ON ev1.IP = ev2.IP AND 
                     ev1.UserID  != ev2.UserID AND
                     ev1.EventTime  &amp;lt;  ev2.EventTime AND
                     TimeDiff(ev2.EventTime, ev1.EventTime) &amp;lt;= 60
WHERE ev1.Action = 'Ban'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How to write such a search in Splunk? &lt;/P&gt;</description>
    <pubDate>Wed, 15 Jun 2016 17:48:55 GMT</pubDate>
    <dc:creator>pm771</dc:creator>
    <dc:date>2016-06-15T17:48:55Z</dc:date>
    <item>
      <title>How do I write this SQL query as a join search in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-this-SQL-query-as-a-join-search-in-Splunk/m-p/211356#M61819</link>
      <description>&lt;P&gt;I will ask my question using online forum as an example.  &lt;/P&gt;

&lt;P&gt;It has Event Log that tracks all user actions from login to logout. Contains the following significant fields: &lt;CODE&gt;EventTime&lt;/CODE&gt;, &lt;CODE&gt;UserID&lt;/CODE&gt;, &lt;CODE&gt;IP address&lt;/CODE&gt;,  &lt;CODE&gt;Action&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;We want to write a search that identifies users that were banned ( &lt;CODE&gt;Action='Ban'&lt;/CODE&gt; ) and then quickly came back under another &lt;CODE&gt;UserID&lt;/CODE&gt;, but still with the same &lt;CODE&gt;IP&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;In SQL I would use the following &lt;CODE&gt;SELF JOIN&lt;/CODE&gt; (assuming &lt;CODE&gt;TimeDiff&lt;/CODE&gt; is a valid function returning seconds): &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SELECT ev1.IP,  ev1.UserID, ev1.EventTime, ev2.UserID, ev2.EventTime, ev2.Action
FROM EventLog ev1
JOIN Eventlog ev2 ON ev1.IP = ev2.IP AND 
                     ev1.UserID  != ev2.UserID AND
                     ev1.EventTime  &amp;lt;  ev2.EventTime AND
                     TimeDiff(ev2.EventTime, ev1.EventTime) &amp;lt;= 60
WHERE ev1.Action = 'Ban'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How to write such a search in Splunk? &lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:48:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-this-SQL-query-as-a-join-search-in-Splunk/m-p/211356#M61819</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2016-06-15T17:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write this SQL query as a join search in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-this-SQL-query-as-a-join-search-in-Splunk/m-p/211357#M61820</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* [search index=* action=* | dedup IP | table IP] | eventstats count by IP | where count&amp;gt;1 | streamstats window=1 current=f latest(_time) as nextattempt by IP | eval time_diff=abs(nextattempt-_time) | where time_diff&amp;lt;=60
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:05:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-this-SQL-query-as-a-join-search-in-Splunk/m-p/211357#M61820</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-06-15T18:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write this SQL query as a join search in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-this-SQL-query-as-a-join-search-in-Splunk/m-p/211358#M61821</link>
      <description>&lt;P&gt;I had an unfortunate typo in my SQL query.  Second line of &lt;CODE&gt;ON&lt;/CODE&gt; condition was incorrect, should've been &lt;CODE&gt;ev1.UserID  != ev2.UserID&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;Now that it's fixed, could you please re-check your answer? &lt;/P&gt;

&lt;P&gt;TIA&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:41:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-write-this-SQL-query-as-a-join-search-in-Splunk/m-p/211358#M61821</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2016-06-15T18:41:27Z</dc:date>
    </item>
  </channel>
</rss>

