Link to home
Start Free TrialLog in
Avatar of Star79
Star79Flag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial