ABSTRACT The size–mass galaxy distribution is a key diagnostic for galaxy evolution. Massive compact galaxies are potential surviving relics of a high-redshift phase of star formation. Some of these could be nearly unresolved in Sloan Digital Sky Survey (SDSS) imaging and thus not included in galaxy samples. To overcome this, a sample was selected from the combination of SDSS and UKIRT Infrared Deep Sky Survey (UKIDSS) photometry to r < 17.8. This was done using colour–colour selection, and then by obtaining accurate photometric redshifts (photo-z) using scaled flux matching (SFM). Compared to spectroscopic redshifts (spec-z), SFM obtained a 1σ scatter of 0.0125 with only 0.3 per cent outliers (|Δln (1 + z)| > 0.06). A sample of 163 186 galaxies was obtained with 0.04 < z < 0.15 over $2300\, {\rm deg}^2$ using a combination of spec-z and photo-z. Following Barro et al. log Σ1.5 = log M* − 1.5log r50, maj was used to define compactness. The spectroscopic completeness was 76 per cent for compact galaxies (log Σ1.5 > 10.5) compared to 92 per cent for normal-sized galaxies. This difference is primarily attributed to SDSS ‘fibre collisions’ and not the completeness of the main galaxy sample selection. Using environmental overdensities, this confirms that compact quiescent galaxies are significantly more likely to be found in high-density environments compared to normal-sized galaxies. By comparison with a high-redshift sample from 3D-HST, log Σ1.5 distribution functions show significant evolution, with this being a compelling way to compare with simulations such as EAGLE. The number density of compact quiescent galaxies drops by a factor of about 30 from z ∼ 2 to log (n/Mpc−3) = − 5.3 ± 0.4 in the SDSS–UKIDSS sample. The uncertainty is dominated by the steep cut off in log Σ1.5, which is demonstrated conclusively using this complete sample.