<?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: Does Spark SQL can perform UPDATE with INNER JOIN and LIKE with '%' + [column] + '%' ? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24989#M17398</link>
    <description>&lt;P&gt;@Hubert Dudek​&amp;nbsp;Hello, I'm having the same issue with using UPDATE in spark sql and came across your answer. When you say "replace source_table_reference with view" in MERGE, do you mean to replace "P" with "VIEW" that looks something as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%sql
MERGE into MASTER.Product VIEW
using LooUp.Lookup_Table_Colors C ON VIEW.Name LIKE '% ' + C.Color_Name + '% (%'
WHEN MATCHED THEN UPDATE set VIEW.Product_Color =C.Color_Name;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2023 04:58:31 GMT</pubDate>
    <dc:creator>oleole</dc:creator>
    <dc:date>2023-03-28T04:58:31Z</dc:date>
    <item>
      <title>Does Spark SQL can perform UPDATE with INNER JOIN and LIKE with '%' + [column] + '%' ?</title>
      <link>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24987#M17396</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I came from MS SQL and just started to learning more about Spark SQL&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is one part that I'm trying to perform. In MS SQL, it can be easily done, but it seems like it doesn't in Spark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, I want to make a simple update to the record, if the color name can be found anywhere before the '(' syntax&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MASTER.Product Table contain name of the product name like 'Spiderman Blue (Dark Blue)'&lt;/P&gt;&lt;P&gt;LooUp.Lookup_Table_Colors Table Contain list of list of colors like 'Red', 'Blue', 'Green', or etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below statement basically will find 'Spiderman Blue (Dark Blue)' and fill [Product_Color] as 'Blue'&lt;/P&gt;&lt;P&gt;This statement works in MS SQL, but it error out on Spark SQL&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	UPDATE P&lt;/P&gt;&lt;P&gt;	SET Product_Color = C.Color_Name&lt;/P&gt;&lt;P&gt;	FROM MASTER.Product P&lt;/P&gt;&lt;P&gt;	INNER JOIN LooUp.Lookup_Table_Colors C&amp;nbsp;&lt;/P&gt;&lt;P&gt; ON &lt;A href="https://P.Name" alt="https://P.Name" target="_blank"&gt;P.Name&lt;/A&gt; LIKE '% ' + C.Color_Name + ' % (%';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error Message: Error in SQL statement: ParseException: &lt;/P&gt;&lt;P&gt;mismatched input 'FROM' expecting {&amp;lt;EOF&amp;gt;, ';'}(line 3, pos 1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I went different route, which is using merge... It didn't error out, but it didn't update any record&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MERGE into MASTER.Product P&lt;/P&gt;&lt;P&gt;using LooUp.Lookup_Table_Colors C ON &lt;A href="https://P.Name" alt="https://P.Name" target="_blank"&gt;P.Name&lt;/A&gt; LIKE '% ' + C.Color_Name + '% (%'&lt;/P&gt;&lt;P&gt;WHEN MATCHED THEN UPDATE set P.Product_Color =C.Color_Name;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there way to do this in Spark SQL? If these syntax doesn't exist in Spark SQL, then is there a different syntax that I could use?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 20:51:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24987#M17396</guid>
      <dc:creator>JJL</dc:creator>
      <dc:date>2022-03-21T20:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Does Spark SQL can perform UPDATE with INNER JOIN and LIKE with '%' + [column] + '%' ?</title>
      <link>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24988#M17397</link>
      <description>&lt;P&gt;I think in MERGE you could replace source_table_reference  with view&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 10:56:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24988#M17397</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-03-22T10:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Does Spark SQL can perform UPDATE with INNER JOIN and LIKE with '%' + [column] + '%' ?</title>
      <link>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24989#M17398</link>
      <description>&lt;P&gt;@Hubert Dudek​&amp;nbsp;Hello, I'm having the same issue with using UPDATE in spark sql and came across your answer. When you say "replace source_table_reference with view" in MERGE, do you mean to replace "P" with "VIEW" that looks something as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%sql
MERGE into MASTER.Product VIEW
using LooUp.Lookup_Table_Colors C ON VIEW.Name LIKE '% ' + C.Color_Name + '% (%'
WHEN MATCHED THEN UPDATE set VIEW.Product_Color =C.Color_Name;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 04:58:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24989#M17398</guid>
      <dc:creator>oleole</dc:creator>
      <dc:date>2023-03-28T04:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Does Spark SQL can perform UPDATE with INNER JOIN and LIKE with '%' + [column] + '%' ?</title>
      <link>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24990#M17399</link>
      <description>&lt;P&gt;I think that's what you meant - it worked for me! Thanks for sharing your knowledge @Hubert Dudek​&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 05:21:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/does-spark-sql-can-perform-update-with-inner-join-and-like-with/m-p/24990#M17399</guid>
      <dc:creator>oleole</dc:creator>
      <dc:date>2023-03-28T05:21:39Z</dc:date>
    </item>
  </channel>
</rss>

