SQL Query on Deleting conditionals

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/68452?pagenum=1
05 November 2025, 04:04

Topic


SiSL
SQL Query on Deleting conditionals
27 March 2009, 19:57


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)

 

Replies ...


Carefree
27 March 2009, 22:09


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"
SiSL
28 March 2009, 04:32


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....
Carefree
28 March 2009, 04:42


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.
© 2000-2021 Snitz™ Communications