SQL Query on Deleting conditionals - نوشته شده در (1006 Views)
Average Member
SiSL
مطلب: 671
671
Greetings again,

I want to delete some records such as:

DELETE FROM TABLE WHERE ID IN (<..various ids>)

So far so good, however, I want to combine where clause to soem other condition on other table...
like DELETE FROM TABLE t1 WHERE t1.ID IN (<..various ids..>) AND t1.DATE < (SELECT t2.ZDATE FROM ANOTHERTABLE t2 WHERE t2.ID = t1.USER )

Will that work? (Don't want to delete any other records on other table)
 پیش‌فرض مرتب‌سازی برای تاریخ DESC به معنی جدیدترین است  
 تعداد در صفحه 
نوشته شده در
Advanced Member
Carefree
مطلب: 4224
4224
Something like this?
Code:

strSql="DELETE * FROM " & strTablePrefix & "T1 AS T INNER JOIN " & strTablePrefix & "T2 AS U ON T.T1.ID=U.T2.ID WHERE T.T1.ID IN (...) AND T.T1.DATE<U.T2.DATE"
نوشته شده در
Average Member
SiSL
مطلب: 671
671
I guess I made it like similiar to first post... not sure if Inner Join would not mess up on delete

I did it like

DELETE FROM TABLE WHERE ID IN (...) AND DATE < (SELECT OTHERDATE FROM ANOTHERTABLE AS AT WHERE AT.ID = USER)

Ofcourse, only thing stopped me doing it was Collations and when fixing collations, it is all done, voila...

Edit: Woha, over 500 posts after years :p I'm a slacker....
نوشته شده در
Advanced Member
Carefree
مطلب: 4224
4224
Using inner join as I typed it will not affect the second table. But if you've got it functioning and are happy with it, that's all that counts.
 
شما باید یک متن وارد کنید