  We generalize the Guth--Katz joints theorem from lines to varieties. A
special case says that $N$ planes (2-flats) in 6 dimensions (over any field)
have $O(N^{3/2})$ joints, where a joint is a point contained in a triple of
these planes not all lying in some hyperplane. More generally, we prove the
same bound when the set of $N$ planes is replaced by a set of 2-dimensional
algebraic varieties of total degree $N$, and a joint is a point that is regular
for three varieties whose tangent planes at that point are not all contained in
some hyperplane. Our most general result gives upper bounds, tight up to
constant factors, for joints with multiplicities for several sets of varieties
of arbitrary dimensions (known as Carbery's conjecture). Our main innovation is
a new way to extend the polynomial method to higher dimensional objects,
relating the degree of a polynomial and its orders of vanishing on a given set
of points on a variety.
