title: How to delete record from database if no longer existed
body: <p>If I have a new data/record in my CSV file then I'm importing it to my SQL Server database using PowerShell like this.</p>
  <pre><code>$CSVImport = Import-CSV $Global:ErrorReport
          ForEach ($CSVLine1 in $CSVImport) {
              $CSVHold1 = $CSVLine1.Hold
              $CSVGSID1 = $CSVLine1.GSID 
              $CSVSource1 = $CSVLine1.Source
              $CSVTYPE1 = $CSVLine1.TYPE
              $CSVMessage1 = $CSVLine1.Message
              $CSVCreatedDate1 = $CSVLine1.Time
  
  
              $query = &quot;USE $Global:Database
                 IF NOT EXISTS (SELECT * FROM Lit_Hold_Err 
                      WHERE GSID = '$CSVGSID1'
                      AND Source = '$($CSVSource1 -replace &quot;'&quot;,&quot;''&quot;)')
                  BEGIN
                  INSERT INTO Lit_Hold_Err (Hold, GSID, Source, Error, Type,Date)
                  VALUES('$CSVHold1', '$CSVGSID1', '$($CSVSource1 -replace &quot;'&quot;,&quot;''&quot;)','$CSVMessage1','$CSVTYPE1', '$CSVCreatedDate1') 
                  END&quot;
             
          Invoke-Sqlcmd -Query $query -ServerInstance $Global:Server -Database $Global:Database
  
  </code></pre>
  <p>I'm just wondering how should I write another query that compare my CSV file with my database and delete a particular/s record from my database if it's no longer existed in my CSV file?.</p>
  <p>I know I'll need to use DELETE Statement but I'm kinda stuck on WHERE Clause so Any help or suggestion would be really appreciated.</p>