SQL phpmyadmin remove posts from cat id exclude condition

finally I find right code with helping by ChatGPT

DELETE p
FROM wp_posts p
INNER JOIN wp_term_relationships tr1 ON (p.ID = tr1.object_id AND tr1.term_taxonomy_id = 2)
LEFT JOIN wp_term_relationships tr2 ON (p.ID = tr2.object_id AND tr2.term_taxonomy_id = 20)
WHERE p.post_type="post"
AND p.post_status="publish"
AND DATEDIFF(NOW(), p.post_date) > 180
AND tr2.term_taxonomy_id IS NULL;

Lets try another way to write new code. consider I want to delete all
posts from category ID 2 in time duration more than 180 days except
those post that are in category ID 20 too . I mean there are for
example 2000 posts in category ID 2 in time duration +180 days and 500
posts of them are in category ID 20 too. so I expect just 1500 posts
will delete and keep those 500 posts.

I try this code and it is working fine

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino