Intersection of open affines can be covered by open sets distinguished in *both*affines

Suppose $X$ is an arbitrary scheme and $U \cong \operatorname{Spec} A$ and $V \cong \operatorname{Spec} B$ are affine upon subsets of $X$. It's not true in general that $U \cap V$ is affine, so if we want to prove basic results about general schemes (e.g. the stuff in section II.3 of Hartshorne), we need some technical means of understanding what goes on on the intersections of open affines.

I've heard that this can be done by covering $U \cap V$ with open sets which are distinguished in both $U$ and $V$, i.e. sets $W \subseteq U \cap V$ with $W \cong \operatorname{Spec} A_f \cong \operatorname{Spec} B_g$ for some $f \in A$ and $g \in B$. I'm having trouble actually proving this.

So, questions:

1. Is this actually true?

2. If so, how are these sets constructed?

-

This is true. For a scheme $X$, let $f$ be a global section of $O_X$. You can construct an open set $X_f$ defined as points where $f$ doesn't vanish, i.e. $\{x \in X: f_x \notin m_x\}$, where $m_x$ is the maximal ideal of the local ring. For affine schemes, this agrees with the usual distinguished open affine $D(f)$. One can also check that if $U \subset X$ is open, then $X_f \cap U = U_{f|_U}$.
In your situation, let $x \in U \cap V$. Take a section $f$ over $U$ such that $x \in D_U(f) \subset U \cap V$ is distinguished in $U$. Take a section $g$ over $V$ such that $x \in D_V(g) \subset D_U(f)$ is distinguished in $V$. The claim is that $D_V(g)$ is also distinguished in $D(f)$, hence in $U$. This is because $D_V(g) = D_{D_U(f)} (g|_{D_U(f)})$.