<?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: How to use the variable haiving set of values in a spark.sql? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-use-the-variable-haiving-set-of-values-in-a-spark-sql/m-p/53301#M29772</link>
    <description>&lt;P&gt;Hello Kaniz, Thanks!&lt;/P&gt;&lt;P&gt;Can I get any reference URL for this content, so that i can see the examples on how to use variables in spark SQL.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Nov 2023 13:58:02 GMT</pubDate>
    <dc:creator>Daniel3</dc:creator>
    <dc:date>2023-11-21T13:58:02Z</dc:date>
    <item>
      <title>How to use the variable haiving set of values in a spark.sql?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-the-variable-haiving-set-of-values-in-a-spark-sql/m-p/50213#M28738</link>
      <description>&lt;P&gt;Hi, I have a set of values to be searched from a table, for which i was trying to assign them to a variable first and then trying to use the variable in spark.sql, but i'm unable to fetch the records. Please see the image attached and correct my code please.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 18:39:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-the-variable-haiving-set-of-values-in-a-spark-sql/m-p/50213#M28738</guid>
      <dc:creator>Daniel3</dc:creator>
      <dc:date>2023-10-31T18:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the variable haiving set of values in a spark.sql?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-the-variable-haiving-set-of-values-in-a-spark-sql/m-p/53301#M29772</link>
      <description>&lt;P&gt;Hello Kaniz, Thanks!&lt;/P&gt;&lt;P&gt;Can I get any reference URL for this content, so that i can see the examples on how to use variables in spark SQL.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 13:58:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-the-variable-haiving-set-of-values-in-a-spark-sql/m-p/53301#M29772</guid>
      <dc:creator>Daniel3</dc:creator>
      <dc:date>2023-11-21T13:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the variable haiving set of values in a spark.sql?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-use-the-variable-haiving-set-of-values-in-a-spark-sql/m-p/53647#M29855</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;One way to address the example provided in your screenshot is by using a combination of a python f-string and a Common Table Expression like shown below. This is assuming that in reality the two tables are different unlike in the provided screenshot. If the query is only against a single table then there is no need for the CTE and the predicate variables can be applied directly against the table.&lt;/P&gt;
&lt;PRE&gt;min_value = 10&lt;BR /&gt;max_value = 20&lt;BR /&gt;sql_statement = f"""with users_with_filter as (&lt;BR /&gt;select user_id from users where user_id between {min_value} and {max_value}&lt;BR /&gt;)&lt;BR /&gt;select *&lt;BR /&gt;from users as u1&lt;BR /&gt;inner join users_with_filter as u2&lt;BR /&gt;on u1.user_id = u2.user_id&lt;BR /&gt;"""&lt;BR /&gt;spark.sql(sql_statement).show()&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2023 14:59:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-use-the-variable-haiving-set-of-values-in-a-spark-sql/m-p/53647#M29855</guid>
      <dc:creator>brockb</dc:creator>
      <dc:date>2023-11-23T14:59:37Z</dc:date>
    </item>
  </channel>
</rss>

