An apparent equivalence of the category of affine schemes over $S$ and the category of quasi-coherent $\mathcal{O}_S$-algebras I had asked something very similar before on math.se (deleted now) but unfortunately it hadn't received a lot of attention. I decided to re-ask here.
Let $S$ be a fixed scheme. Is the following true?

Theorem(?): The category of affine schemes over $S$ is contra-equivalent to the category of quasi-coherent $\mathcal{O}_S$-algebras

Here the category of affine scheme over $S$ is one whose objects are arrows $\operatorname{Spec} A \to S$ where $A$ ranges over all possible rings and whose morphisms are morphisms of schemes above $S$. Here's the construction:
Let $\varphi: \mathcal{O}_S  \to \mathcal{F}$ be an $\mathcal{O}_S$-algebra.


*

*Let $X$ be the set of all prime ideal sub-sheafs $\mathcal{P} \subset \mathcal{F}$. That is $\mathcal{P}(U)$ is either a prime or a unit on every open set $U \subset S$.

*Define a topology with open sets of the form $V_{U,s} = \{\mathcal{P} \in X: s \notin \mathcal{P}(U)\}$ for open sets $U \subset S$ and $s \in \mathcal{F}(U)$. 

*Define the structure sheaf by localizing $\mathcal{O}_X  (V_{U,s})=\mathcal{F}(U)_s$.

*The morphism $X \to S$ that sends a prime sheaf to its pullback by $\varphi$ can be seen to satisfy the requirements. 


The inverse functor is the obvious one that sends structure sheafs to their pushforwards.
Recently I found that this equivalence supports a very slick argument that the intersection of affines are affine - which I very much suspect is not true. Here is the (probably false) argument:

Let $\operatorname{Spec} A \hookrightarrow S$ and $\operatorname{Spec} B \hookrightarrow S$ be affine subschemes. Being affine schemes over $S$ they can be considered as $\mathcal{O}_S$-algebras. Their intersection is the pullback which corresponds to their tensor product as $\mathcal{O}_S$-algebras. This gives another $\mathcal{O}_S$-algebra i.e. an affine scheme over $S$. We're done.

What are the flaws in the argument/theorem?
 A: No, it's not true in general (EGA 2, (1.2.3)). 
The following example is taken from EGA 2, (1.3.3). Over a field $K$, let $S$ be the affine plane with a doubled origin. Then $S$ is the union of two affine open subsets $Y_1$ and $Y_2$, each of them is isomorphic to the affine plane, glued along the complementary subset of their origin. In particular, $Y_1$ is affine, but the open immersion $j\colon Y_1\to S$ is not an affine morphism because the inverse image of $Y_2$ is $Y_1\cap Y_2$,
the plane minus the origin, which is not an affine scheme.
On the other hand, if $S$ is separated, then the intersection of two open affine subschemes is affine, and this will imply that your desired result holds true (see EGA 1 (5.5.10)).
Finally, the other direction does not work either: every scheme, be it affine or not, is affine over itself.
A: What is true is that there is an antiequivalence between the category of schemes affine over $S$ (that is $S$-schemes for which the preimage of an open affine of $S$ is an open affine) and quasi-coherent $\mathcal{O}_S$-algebras. 
The anti-equivalence is realized by the pushforward of the structure sheaf and the relative spectrum (see Exercise 5.17 in Hartshorne's "Algebraic Geometry"). This is of course not the result you hoped for, but maybe it is still interesting.
