Delete with INNER JOINS

Hi,

I have the following SQL Query which does the update but for better performance i want to delete and then insert rather than updating, following is a update procedure, can anyone please give the query to Delete the records with following update criteria. With inner joins Deletion for me is getting little complex.

UPDATE Table1
SET
      first_name = MTab2.FirstName
      ,last_name = MTab2.LastName
      ,update_date = GETDATE()
      FROM Table2 MTab2
            INNER JOIN [Table3] Mtab3
                  ON MTab2.CompanyId = Mtab3.CompanyID AND Is_EPA != 1
            INNER JOIN [Table4]
                  ON [Table4].[id] = (SELECT id FROM Table4 WHERE id = Mtab3.Id AND RequiredEnt=1)
      WHERE
            MTab2.UpdateOn > (SELECT  MAX(Updated_date) FROM TABLE4)
            AND [Table1].[id] > 500


Thanks,
Rithesh
Star79Asked:
Who is Participating?
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
delete Table1
FROM Table2 MTab2
    INNER JOIN [Table3] Mtab3
          ON MTab2.CompanyId = Mtab3.CompanyID AND Is_EPA != 1
    INNER JOIN [Table4]
          ON [Table4].[id] = (SELECT id FROM Table4 WHERE id = Mtab3.Id AND RequiredEnt=1)
WHERE
    MTab2.UpdateOn > (SELECT  MAX(Updated_date) FROM TABLE4)
    AND [Table1].[id] > 500
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.