I have 2 tables:
- FirstTable
- SecondTable
FirstTable has these columns
sales_ID varchar(250)
product_ID int
SecondTable has these columns
sales_ID varchar(250)
product_ID int
CreateDate datetime
If FirstTable's sales_ID and product_ID match to SecondTable's sales_Id and product_ID, and also if SecondTable's CreatedDate is 07.04.2015, I need to delete the row from SecondTable
I tried like this:
delete from SecondTable
WHERE sales_Id IN (SELECT sales_Id FROM FirstTable)
and product_ID IN (SELECT product_ID FROM FirstTable)
and CreatedDate = '07-04-2015'
However it deletes all rows and also it is not correct (not working) query according to what I want.
How can I delete duplicate rows if product_ID equals product_ID and sales_ID equal sales_ID and CreatedDate equals 07.04.2015 from SecondTable?
Hope you understand my bad english
Thanks.