> DELETE FROM B
> WHERE r_id IN (SELECT R.id
> FROM R, B
> WHERE r.end_date < (NOW() - (interval '1 day' * 30))
> AND r.id = b.r_id
>
How about:
DELETE FROM B
WHERE r_id IN (SELECT distinct R.id
FROM R WHERE r.end_date < (NOW() - (interval '1 day' * 30))
?
Greetings
Marcin