<?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: Deleting from lakehouse table based on values in another lakehous table in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Deleting-from-lakehouse-table-based-on-values-in-another/m-p/3708999#M1187</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="582610" data-lia-user-login="ebjim" class="lia-mention lia-mention-user"&gt;ebjim&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I tried to repro the same scenario from my side. I have 2 tables with same schema in my lakehouse :&lt;BR /&gt;&lt;BR /&gt;1) List with 40 rows &lt;BR /&gt;2) Listings_3 with 45 rows. &lt;BR /&gt;I tried to delete the 40 rows in Listings_3 with the below code: &lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The rows got successfully deleted. SQL MERGE is faster when compared to other DML operations. By using the MERGE statement, you can replace the individual DML statements with a single statement. This can improve query performance because the operations are performed within a single statement, therefore, minimizing the number of times the data in the source and target tables are processed. &lt;BR /&gt;&lt;BR /&gt;Please try this approach and do let me know if you have any further questions. Hope this helps.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Feb 2024 20:44:09 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-02-19T20:44:09Z</dc:date>
    <item>
      <title>Deleting from lakehouse table based on values in another lakehous table</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Deleting-from-lakehouse-table-based-on-values-in-another/m-p/3708945#M1185</link>
      <description>&lt;P&gt;I have 2 tables in the same lakehouse and one of them (existingData) has rows that need to be deleted, based on what's in the other table (newData). Whatever IDs found in newData are the rows that need to be deleted from existingData. The two tables have identical structure, but the IDs in newData are not continuous, so I cannot delete based on range. Also, subqueries are not supported in Spark SQL. Delete queries using inner join didn't work. I ended up using this PySpark loop but it's slow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;LakehouseName = &lt;/SPAN&gt;&lt;SPAN&gt;"Lakehouse"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;TableOri = &lt;/SPAN&gt;&lt;SPAN&gt;"existingData"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;TableDest = &lt;/SPAN&gt;&lt;SPAN&gt;"newData"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ColName = &lt;/SPAN&gt;&lt;SPAN&gt;"ID"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ToDelete = spark.sql(&lt;/SPAN&gt;&lt;SPAN&gt;"SELECT &lt;/SPAN&gt;&lt;SPAN&gt;{0}&lt;/SPAN&gt;&lt;SPAN&gt; FROM &lt;/SPAN&gt;&lt;SPAN&gt;{1}&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;{2}&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;.format(ColName,LakehouseName,TableDest)).collect()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;for&lt;/SPAN&gt;&lt;SPAN&gt; row &lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt; ToDelete:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; spark.sql(&lt;/SPAN&gt;&lt;SPAN&gt;"DELETE FROM &lt;/SPAN&gt;&lt;SPAN&gt;{0}&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;{1}&lt;/SPAN&gt;&lt;SPAN&gt; WHERE &lt;/SPAN&gt;&lt;SPAN&gt;{2}&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;{3}&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;.format(LakehouseName, TableOri, ColName, row[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any ideas for something quicker? Thanks in advance!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 19 Feb 2024 19:48:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Deleting-from-lakehouse-table-based-on-values-in-another/m-p/3708945#M1185</guid>
      <dc:creator>ebjim</dc:creator>
      <dc:date>2024-02-19T19:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting from lakehouse table based on values in another lakehous table</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Deleting-from-lakehouse-table-based-on-values-in-another/m-p/3708952#M1186</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="582610" data-lia-user-login="ebjim" class="lia-mention lia-mention-user"&gt;ebjim&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thanks for using Fabric Community.&lt;BR /&gt;At this time, we are reaching out to the internal team to get some help on this. We will update you once we hear back from them. &lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 19:58:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Deleting-from-lakehouse-table-based-on-values-in-another/m-p/3708952#M1186</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-19T19:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting from lakehouse table based on values in another lakehous table</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Deleting-from-lakehouse-table-based-on-values-in-another/m-p/3708999#M1187</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="582610" data-lia-user-login="ebjim" class="lia-mention lia-mention-user"&gt;ebjim&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I tried to repro the same scenario from my side. I have 2 tables with same schema in my lakehouse :&lt;BR /&gt;&lt;BR /&gt;1) List with 40 rows &lt;BR /&gt;2) Listings_3 with 45 rows. &lt;BR /&gt;I tried to delete the 40 rows in Listings_3 with the below code: &lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The rows got successfully deleted. SQL MERGE is faster when compared to other DML operations. By using the MERGE statement, you can replace the individual DML statements with a single statement. This can improve query performance because the operations are performed within a single statement, therefore, minimizing the number of times the data in the source and target tables are processed. &lt;BR /&gt;&lt;BR /&gt;Please try this approach and do let me know if you have any further questions. Hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 20:44:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Deleting-from-lakehouse-table-based-on-values-in-another/m-p/3708999#M1187</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-19T20:44:09Z</dc:date>
    </item>
  </channel>
</rss>

