RamSteve (10/7/2013)
Hi i do not want to delete consumerID 100 as deleteflag is 0 for one productand moreover this is not a home work , but i am trying to do it in a simple way for the below query
DELETE Table A
FROM TableA a
INNER JOIN TableB b ON b.ConsumerID = a.ConsumerID
WHERE a.ConsumerID IN
(
SELECT ConsumerID FROM TableB WHERE DeleteFlag= 1 AND ConsumerID NOT IN (SELECT Consumer_ID FROM Visitor_By_Brand WHERE Delete_Flag =0 )
)
Your query as posted here would still delete 100 assuming there is not a record in Visitor_By_Brand where Delete_Flag = 0 for that consumer.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/