Let $X$ be $\mathcal{F}$-measurable with $\mathbb{E}(X^2)<\infty$ and let $\mathcal{G}\subset\mathcal{F}$ be a $\sigma$-algebra. Show that $$\mathbb{E}([X-\mathbb{E}(X|\mathcal{G})]^2|\mathcal{G})=\mathbb{E}(X^2|\mathcal{G})-\mathbb{E}(X|\mathcal{G})^2$$ I'm having trouble because, to have $\mathbb{E}(X\mathbb{E}(X|\mathcal{G})|\mathcal{G})=\mathbb{E}(X|\mathcal{G})\mathbb{E}(X|\mathcal{G})$ (i.e. to take the $\mathbb{E}(X|\mathcal{G})$ outside) we need $\mathbb{E}(|X\mathbb{E}(X|\mathcal{G})|)<\infty$, which of course doesn't hold immediately now (it should hold of course, though, since eventually, after proving everything, $|\mathbb{E}(X|\mathcal{G})|\leq\sqrt(\mathbb{E}(X^2|\mathcal{G}))<\infty$) .
So I'm trying the following. Prove formula for bounded $X$ (easy) and then in the general case, take the truncation $X_{n}$ (below by $-n$ and above by $n$) of $X$ and use the convergence theorem for conditional expectation.
I can't make it work though, but I know it must be the way. Please help, this is not homework.