Let $\Bbbk$ be an algebraically closed field of characteristic $0$ (just to keep it simple). Assume we are given three affine sets $X\subseteq\mathbb{A}_{\Bbbk}^n,Y\subseteq\mathbb{A}_{\Bbbk}^m$ and $Z\subseteq\mathbb{A}_{\Bbbk}^l$ and two polynomial maps $f:X\to Z$ and $g:Y\to Z$. I would like to show that $$X\times_Z Y:=\left\{(a,b)\in X\times Y\mid f(a)=g(b)\right\}$$ is an affine set by providing explicitly its vanishing ideal.
Assume that $\Bbbk[X]=\Bbbk[X_1,\ldots,X_n]/\langle p_1,\ldots,p_r\rangle, \Bbbk[Y]=\Bbbk[Y_1,\ldots,Y_m]/\langle q_1,\ldots,q_s\rangle$ and that $\Bbbk[Z]=\Bbbk[Z_1,\ldots,Z_l]/\langle o_1,\ldots,o_t\rangle$. My guess is that $$\mathcal{J}(X\times_Z Y)=\langle P_1,\ldots,P_n,Q_1,\ldots,Q_m,Z_1( F-G),\ldots,Z_l(F-G)\rangle\subseteq \Bbbk[X_1\ldots,X_n,Y_1\ldots,Y_m],$$ where $$ P_i(X_1,\ldots,X_n,Y_1,\ldots,Y_m)=p_i(X_1,\ldots,X_n), \\ Q_j(X_1,\ldots,X_n,Y_1,\ldots,Y_m)=q_j(Y_1,\ldots,Y_m), \\ \big(Z_k(F-G)\big)(X_1,\ldots,X_n,Y_1,\ldots,Y_m) = f_k(X_1,\ldots,X_n)-g_k(Y_1,\ldots,Y_m) $$ (the $k$-th component of the polynomial functions). It's not difficult to show that $$ \mathcal{J}(X\times_Z Y)\supseteq\langle P_1,\ldots,P_n,Q_1,\ldots,Q_m,Z_1( F-G),\ldots,Z_l(F-G)\rangle $$ but I am having some troubles in showing the converse.
Does anybody have an idea?