Use the definitions of mean
μ1:n=1n∑i=1nxi
and sample variance
σ21:n=1n∑i=1n(xi−μ1:n)2=n−1n(1n−1∑i=1n(xi−μ1:n)2)
(the last term in parentheses is the unbiased variance estimator often computed by default in statistical software) to find the sum of squares of all the data xi. Let's order the indexes i so that i=1,…,n designates elements of the first group and i=n+1,…,n+m designates elements of the second group. Break that sum of squares by group and re-express the two pieces in terms of the variances and means of the subsets of the data:
(m+n)(σ21:m+n+μ21:m+n)=∑i=11:n+mx2i=∑i=1nx2i+∑i=n+1n+mx2i=n(σ21:n+μ21:n)+m(σ21+n:m+n+μ21+n:m+n).
Algebraically solving this for σ2m+n in terms of the other (known) quantities yields
σ21:m+n=n(σ21:n+μ21:n)+m(σ21+n:m+n+μ21+n:m+n)m+n−μ21:m+n.
Of course, using the same approach, μ1:m+n=(nμ1:n+mμ1+n:m+n)/(m+n) can be expressed in terms of the group means, too.
An anonymous contributor points out that when the sample means are equal (so that μ1:n=μ1+n:m+n=μ1:m+n), the solution for σ2m+n is a weighted mean of the group sample variances.