This is a problem from Durret's probability textbook. Show that if $X,Y$ are random variables with $E(Y|\mathcal{G})=X$ and $EY^2=EX^2\leq\infty$, then $X=Y$ a.s.
My question is, by the definition of conditional expectation, $\forall A\in \mathcal{F}$, $$\int_{A} YdP = \int_{A} E(Y|\mathcal{G})dP=\int_{A} XdP$$ Doesn't this already imply that $X=Y$ a.s? Why do we need the condition that $EY^2=EX^2\leq\infty$?