I am just learning the sql. I have this query and trying to optimize the query rewriting.Please help me out more efficient way of writing this query--Thanks!!
DECLARE @Test TABLE ( ID INT ,DetailID INT , PrevID INT );
INSERT INTO @Test ( ID , DetailID ,SaleID)
SELECT a.ID , a.DetailID ,b.PrevID FROM tbla A
LEFT JOIN TBLb B ON A.id = B.id;
DELETE FROM tbla WHERE id IN ( SELECT ID FROM @Test );
UPDATE tblc SET Flag = 'y'
WHERE id IN ( SELECT ID FROM @Test UNION ALL SELECT PrevID FROM @Test );