Can someone help me rewrite this pseudo code into ansi sql syntax?

We have 3tables:
TABP
---
a
b

TABQ
---
b
c
d

TABR
---
a
c
d


Update TABR R set R.d =
(
select Q.d from TABQ Q, TABP P
where Q.b=P.b
and R.a=P.a
)
where R.d=-1

I tried but the explain showed nested loops and is running too long
Thanks
sri