Splunk Search

Join 3 Queries into one for usage in Dashboard

kishorksudha
Explorer

I am getting the feeds from Database into Splunk every 15 minutes; using 3 Queries to get the desired results; can you please help me to combine all these three into a single query
Step 1: Find all the Unique IDS (PAY_TXN_ID)
index=foo source="dbmon-tail://Dev/test-DEV" | dedup PAY_TXN_ID | table PAY_TXN_ID
Step2: For each of the Unique IDS obtained from previous query; get the latest Time stamp (AUDIT_TIME)
index=foo source="dbmon-tail://Dev/test-DEV" | search PAY_TXN_ID="3225958" | table AUDIT_TIME | sort -AUDIT_TIME | head 1
Step3: For each of the Unique IDS PAY_TXN_ID (step1)and the latest Time Stamp for that ID(step 2) get all the required details - Desired Results
index=foo source="dbmon-tail://Dev/test-DEV" | search PAY_TXN_ID="3225958" | search AUDIT_TIME="1345618062.375" | table PAY_TXN_ID, SOURCE, STATUS, DEBIT_CCY, DEBIT_AMNT, REMIT_CCY, REMIT_AMNT

Can someone help me to convert these three queries into a single one.

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Try this:

index=foo source="dbmon-tail://Dev/test-DEV" | eventstats max(AUDIT_TIME) as max_audit_time by PAY_TXN_ID | where AUDIT_TIME = max_audit_time | table PAY_TXN_ID, SOURCE, STATUS, DEBIT_CCY, DEBIT_AMNT, REMIT_CCY, REMIT_AMNT

NB: I have assumed that AUDIT_TIME values are unique per PAY_TXN_ID. If that's not the case you will get all events with the latest AUDIT_TIME for one PAY_TXN_ID.

View solution in original post

kishorksudha
Explorer

Thank you very much Martin; it was very helpful.
your assumption was right; AUDIT_TIME values are unique per PAY_TXN_ID.
AUDIT_TIME is the rising_column when the datas are being pulled from the Database.

Thanks
Kishor

0 Karma

echalex
Builder

Hi kishorksudha. If Martin's answer was helpful, I suggest you click on "accept answer" and possibly vote up the answer as well. Furthermore, the preferred way of replying would be to comment on the answer, rather than posting a new answer.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Try this:

index=foo source="dbmon-tail://Dev/test-DEV" | eventstats max(AUDIT_TIME) as max_audit_time by PAY_TXN_ID | where AUDIT_TIME = max_audit_time | table PAY_TXN_ID, SOURCE, STATUS, DEBIT_CCY, DEBIT_AMNT, REMIT_CCY, REMIT_AMNT

NB: I have assumed that AUDIT_TIME values are unique per PAY_TXN_ID. If that's not the case you will get all events with the latest AUDIT_TIME for one PAY_TXN_ID.

kishorksudha
Explorer

Thanks Martin
It was very helpful and the assumption was right.

Kishor

0 Karma
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 ...