An understanding of the formation, evolution and eventual fate of galaxies and large-scale structures requires statistically complete, robust and well-defined samples of galaxies spanning the largest possible range in redshifts. The UltraVISTA-COSMOS survey, by combining multi-wavelength images with ultra-deep infrared data and applying a unique calbration sample of tens of thousands of spectroscopic redshifts, has enabled us to derive precise photometric redshifts and stellar masses for a large sample of galaxies out to z~6. In my talk I will present results using each of the UltraVISTA public data releases. From this unique stellar-mass-selected sample one can investigate the relationship between galaxies and the dark matter haloes hosting them over more than half of the age of the universe. I will discuss the implications this work has for galaxy formation efficiency and the fate of satellite galaxies in dark matter haloes. Finally, I will describe how the addition of Hyper Suprime-Cam data further increases the value of the COSMOS-UltraVISTA dataset.