Subset of Spec(A) realized as inverse image of some Spec(B) Let $A$ be a (commutative) ring and $U$ be an arbitrary subset of $\mathrm{Spec}(A)$. Do there exist a ring $B$ and a ring homomorphism $\varphi\colon A\to B$ such that $\varphi^{-1}(\mathrm{Spec}(B))=U$ ? If $\varphi\colon A\to B$ and $\varphi'\colon A\to B'$ are two ring homomorpisms such that $\varphi^{-1}(\mathrm{Spec}(B))=\varphi'^{-1}(\mathrm{Spec}(B'))=U$, do there exist a ring homomorpism $f\colon B\to B'$ such that $f\varphi=\varphi'$ ?
 A: For the first question, $\mathrm{Spec}(B)$ is quasi-compact for every ring $B$, so if $U\subset\mathrm{Spec}(A)$ is not quasi-compact, then there cannot exist $f:A\to B$ with $U=f^*(\mathrm{Spec}(B))$. An example of this is $A=k[x_1,x_2,\ldots]$ a polynomial ring over a field $k$ in countably many variables, 
$$
U=\mathrm{Spec}(A)\backslash\{(x_1,x_2,\ldots)\}.
$$
Then
$
U_n:=D(x_1,\ldots,x_n)
$, $n=1,2,\ldots$,
is an open cover of $U$ that has no finite subcover, so $U$ cannot be the the image of any $\varphi^*:\mathrm{Spec}(B)\to\mathrm{Spec}(A)$. I would be interested to know if there is a counterexample with $A$ Noetherian.
For the second question, take $A=\mathbb{Z}$, $B=\mathbb{Z}/(p)$, $B'=\mathbb{Z}/(p^2)$, $p$ a prime, and $\varphi,\varphi'$ the quotient maps. Then $\varphi^*(\mathrm{Spec}(B))=(\varphi')^*(\mathrm{Spec}(B'))=\{(p)\}$, but there don't exist any ring homomorphisms $B\to B'$.
A: As an addition to Julian Rosen's answer, here is an example with $A$ noetherian and $U$ quasicompact: take $A=\mathbb{Z}$ (or any PID with infinitely many primes), and $U$ = any infinite set of closed points. Assume $B$ is a ring such that the image of $\mathrm{Spec}(B)$ to $\mathrm{Spec}(\mathbb{Z})$ is $U$. Since $U$ does not contain the generic point, we have $\mathbb{Q}\otimes_\mathbb{Z}B=0$. In particular, there is a nonzero integer $n$ such that $n1_B=0$, so  $\mathrm{Spec}(B)$ maps to the finite set of divisors of $n$: contradiction.
A: There are already two nice counterexamples. Let me just point out for question (1) a characterization of images of $\mathrm{Spec}(B)$ in $X:=\mathrm{Spec}(A)$: 

A subset $U$ of $X$ is the image of some $\mathrm{Spec}(B)\to X$ if and only if $U$ is pro-constructible. 

See EGA IV.1.9.5. In a noetherian space, $U$ is pro-constructible if it is an arbitrary intersection of constructible subsets (i.e. finite unions of locally closed subsets) of $X$.  A constructible subset of $\mathrm{Spec}(\mathbb Z)$ (or any irreducible noetherian scheme of dimension $1$) is either finite or contains the generic point, so a pro-constructible subset is either finite or contains the generic point. This "explains" the example of Laurent. 
