Splunk Search

Left Outer Join in Splunk

yaswanth1992
New Member

Below is our Requirement

Lookup file has just one column DatabaseName, this is the left dataset

DatabaseName
A
B
C

 

My Search is for metrics on databases and ha

s multiple rows, this is the right dataset

DatabaseNameInstanceCPUUtilization
AA110
AA220
CC140
CC250
DD60

 

Expected Result is this after left join

DatabaseNameInstanceCPUUtilization
AA110
AA220
BNULLNULL
CC140
CC250

 

But when I join using DatabaseName, I am getting only three records, 1 for A, 1 for B with NULL and 1 for C

My background is SQL and for me left join is all from left data set and all matching from right data set. So please suggest me how I can achive this.

Labels (2)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

one old answer which describe how joins can/should do with splunk https://community.splunk.com/t5/Splunk-Search/What-is-the-relation-between-the-Splunk-inner-left-joi...

r. Ismo

0 Karma

fredclown
Builder

Something like this should work. I called the lookup db_names.csv ... change that to whatever your actual lookup is named. Everything above the comment just emulates the data you gave.

| makeresults count=1
| eval _raw="DatabaseName,Instance,CPUUtilization
A,A1,10
A,A2,20
C,C1,40
C,C2,50
D,D,60"
| multikv forceheader=1
| fields - _time, _raw, linecount
```^^^^ This emulates the data you gave ^^^^```
| eval inst_cpu=Instance+"#"+CPUUtilization
| fields - Instance CPUUtilization
| inputlookup db_names.csv append=true ```<-- change the lookup name here```
| stats list(inst_cpu) as inst_cpu by DatabaseName
| mvexpand inst_cpu
| eval Instance=mvindex(split(inst_cpu,"#"), 0)
| eval CPUUtilization=mvindex(split(inst_cpu,"#"), 1)
| fillnull value="NULL" Instance CPUUtilization
| fields - inst_cpu

 

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The join command is an inefficient way to combine datasets.  Alternative commands are described in the Search Reference manual (https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/Join#Alternative_commands).

Splunk has a manual for SQL users.  See https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SQLtoSplunk

---
If this reply helps you, Karma would be appreciated.

somesoni2
Revered Legend

For your requirement, left join may not be ideal. Try this alternate implementation (replace make results query with your lookup/data query):

| makeresults | eval DatabaseName=split("A B C"," ") | mvexpand DatabaseName | table DatabaseName | eval from="Lookup" | append [| makeresults | eval DatabaseName=split("A	A1	10#A	A2	20#C	C1	40#C	C2	50#D	D	60","#") | mvexpand DatabaseName | table DatabaseName | rex field=DatabaseName "^(?<DatabaseName>\S+)\s+(?<Instance>\S+)\s+(?<CPUUtilization>\S+)$" | eval from="search"] | eventstats values(from) as from by DatabaseName | where isnotnull(mvfilter(match(from,"Lookup"))) | foreach CPUUtilization Instance [| eval "<<FIELD>>"=coalesce('<<FIELD>>',if(mvcount(from)=1 AND from="Lookup","NULL",null()))] | stats count by DatabaseName CPUUtilization Instance | table DatabaseName CPUUtilization Instance
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...