select ∗ from R as R1
where NOT EXISTS (select ∗ from R where B=R1.A)
this is co-related sub-query. for every row of the outer query the sub-query will be evaluated
first row for R1-> R1(1, NULL) here R1.A=1, R1.B=NULL
we check which tuples of R satisfies the condition in the sub-query => B=R1.A
so it will returns all those tuples where B=1. there is only one such tuple <2,1>
now NOT EXISTS clause will return true if the sub-query evaluates no rows
here for R1(1, NULL) the sub-query returns one such. Thus, the NOT EXISTS clause evaluates to false
for the row R1(2,1) the sub-query returns <1, NULL>, here B=1 and R1.A=1
again the NOT EXISTS clause evaluates to false as the sub-query doesn't returns empty set
R1(3,2) here R1.A=3, R1.B=3
there is not such row in R such that R1.A=B=3 so NOT EXISTS condition evaluates to true
similarly when you check for R1(4,2) NOT EXIST will return true
so the number of tuples=2