<?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: Combining the results of two sql queries from two databases using join command not working in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Combining-the-results-of-two-sql-queries-from-two-databases/m-p/702210#M116161</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/273269"&gt;@BKDRockz&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I undertand that in this way you don't consume license but using dbxquery in searches isn't the best approach to extract data from a database because the db-connect is a very slow extracting tool.&lt;/P&gt;&lt;P&gt;The best approach is to extract data separately using both the queries saving results in an index and then using the indexed data for a search.&lt;/P&gt;&lt;P&gt;In addition don't use join because it's a very slow command: you can dind in Community many examples of correlation searches.&lt;/P&gt;&lt;P&gt;I hint to redesign your ingestion and search process.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2024 18:29:09 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2024-10-17T18:29:09Z</dc:date>
    <item>
      <title>Combining the results of two sql queries from two databases using join command not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Combining-the-results-of-two-sql-queries-from-two-databases/m-p/702148#M116159</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;I am fetching unique "ITEM" values from first sql query running on one database. Then passing those values to another sql query to fetch the corresponding values in the second database.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;first SQL query:&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;select distinct a.item from price a, skus b, deps c,supp_country s
where zone_id in (5, 25)
and a.item = b.sku
and b.dept = c.dept
and a.item = s.item and s.primary_supp_ind = 'Y' and s.primary_pack_ind = 'Y'
and b.dept in
(7106, 1666, 1650, 1651, 1654, 1058, 4158, 4159, 489, 491, 492, 493, 495, 496, 497, 498, 499, 501, 7003, 502, 503, 7004, 450,
451, 464, 465, 455, 457, 458, 459, 460, 461, 467, 494, 7013, 448, 462, 310, 339, 7012, 7096, 200, 303, 304, 1950, 1951, 1952,
1970, 1976, 1201, 1206, 1207, 1273, 1352, 1274, 1969, 1987, 342, 343, 7107, 7098, 7095, 7104, 2101, 2117, 7107, 7098, 1990, 477,
162, 604, 900, 901, 902, 903, 904, 905, 906, 908, 910, 912, 916, 918, 7032, 919, 7110, 7093, 7101, 913, 915, 118, 119, 2701, 917)
and b.js_status in ('CO');
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Second SQL:&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;WITH RankedData AS
(SELECT Product_Id,
BusinessUnit_Id,
Price,
LastUpdated,
ROW_NUMBER()
OVER (PARTITION BY Product_Id, BusinessUnit_Id
ORDER BY LastUpdated DESC) AS RowNum
FROM RETAIL.DBO.CAT_PRICE(nolock)
WHERE BusinessUnit_Id IN ('zone_5', 'zone_25')
AND Product_Id IN ($ITEM$) )
SELECT Product_Id,
BusinessUnit_Id,
Price,
LastUpdated
FROM RankedData
WHERE RowNum = 1;&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;When I am using map command as shown below, expected results are fetched but only 10k records as per map command limitations. But I want to to fetch all the records(around 30K)&lt;STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Splunk query:&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| dbxquery query="First SQL query" connection="ABC"
|eval comma="'"
|eval ITEM='comma' + 'ITEM' + 'comma'+","
|mvcombine ITEM
|nomv ITEM
|fields - comma
|eval ITEM=rtrim(tostring(ITEM),",")| map search="| dbxquery query=\"Second SQL query" connection=\"XYZ\""&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;But when i am using join command as shown below to get all the results(more than 10K), I am not getting the desired output. The output only contains results from first query.&lt;BR /&gt;I tried replacing the column name&amp;nbsp;&lt;STRONG&gt;Product_Id &lt;/STRONG&gt;in second sql with&lt;STRONG&gt; ITEM &lt;/STRONG&gt;at all places, but still no luck.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| dbxquery query="First SQL query" connection="ABC"
|fields ITEM
| join type=outer ITEM[search dbxquery query=\"Second SQL query" connection=\"XYZ\""&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;Could someone help me in understanding what is going wrong and how can i get all the matching results from second query?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2024 16:40:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Combining-the-results-of-two-sql-queries-from-two-databases/m-p/702148#M116159</guid>
      <dc:creator>BKDRockz</dc:creator>
      <dc:date>2024-10-17T16:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Combining the results of two sql queries from two databases using join command not working</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Combining-the-results-of-two-sql-queries-from-two-databases/m-p/702210#M116161</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/273269"&gt;@BKDRockz&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I undertand that in this way you don't consume license but using dbxquery in searches isn't the best approach to extract data from a database because the db-connect is a very slow extracting tool.&lt;/P&gt;&lt;P&gt;The best approach is to extract data separately using both the queries saving results in an index and then using the indexed data for a search.&lt;/P&gt;&lt;P&gt;In addition don't use join because it's a very slow command: you can dind in Community many examples of correlation searches.&lt;/P&gt;&lt;P&gt;I hint to redesign your ingestion and search process.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2024 18:29:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Combining-the-results-of-two-sql-queries-from-two-databases/m-p/702210#M116161</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2024-10-17T18:29:09Z</dc:date>
    </item>
  </channel>
</rss>

