Splunk Search

dbconnect returning data from 2 db's with same field names

Cuyose
Builder

Splunk doesn't seem to work with the AS operator in SQl, but rather expects you to RENAME after the query. But what do you do if the query returns the same field name in 2 dbs like this? When I try to rename off the "m.first_name" it doesnt work.

| dbquery DATABASE " SELECT m.first_name AS mFirstName,
mb.first_name AS mb_firstname
FROM DATABASE.TABLE1 m,

DATABASE.TABLE2 mb

WHERE m.id = mb.entity_id"

0 Karma
1 Solution

HiroshiSatoh
Champion

As some other threads, "AS alias" does not work properly status quo.
I have escaped that you do the following.

ex.
m.first_name+"" AS mFirstName, mb.first_name+"" AS mb_firstname

View solution in original post

rdownie
Communicator

You can use the Advanced setting when you create your lookup and rename it in the SQL query there. Then it will return as any name you want it to. I had to do this with spaces in column names which Splunk did not know how to handle and it worked great.

0 Karma

HiroshiSatoh
Champion

As some other threads, "AS alias" does not work properly status quo.
I have escaped that you do the following.

ex.
m.first_name+"" AS mFirstName, mb.first_name+"" AS mb_firstname

Cuyose
Builder

Bam this worked! Thank you!

0 Karma

HiroshiSatoh
Champion

If I could use TRIM, I want you to try and TRIM

trim(m.first_name) AS mFirstName, trim(mb.first_name) AS mb_firstname

Cuyose
Builder

The first and last names from both tables have values when just running the query against the SQL db. When adding the suggested (AS) syntax fix to the splunk dbquery the new field names are now displayed in the results from the new search but all the first and last name fields for the renamed table return 0's and not the data from the db.

0 Karma

HiroshiSatoh
Champion

What data do you missing? Regularity or is likely something?
My environment is MySQL Server 5.5.

0 Karma

Cuyose
Builder

This returns the columns now, but doesn't return any data for those renamed columns. running in sql works fine though.

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...