We present a sample of 8498 quasars with both Sloan Digital Sky Survey (SDSS) ugriz optical and United Kingdom Infrared Telescope (UKIRT) Infrared Deep Sky Survey (UKIDSS) YJHK near-infrared (near-IR) photometric data. With this sample, we obtain the median colour–z relations based on 7400 quasars with magnitude uncertainties less than 0.1 mag in all bands. By analysing the quasar colours, we propose an empirical criterion in the Y−K versus g−z colour–colour diagram to separate stars and quasars with redshift z < 4, and two other criteria for selecting high-redshift quasars. Using the SDSS–UKIDSS colour–z relations, we estimate the photometric redshifts of 8498 SDSS–UKIDSS quasars, and find that 85.0 per cent of them are consistent with the spectroscopic redshifts within |Δz| < 0.2, which leads to a significant increase of the photometric redshift accuracy from that based on the SDSS colour–z relations only. As two tests, we compare our colour-selection criterion with a small UKIDSS/EDR quasar/star sample and a sample of 4671 variable sources in the SDSS Stripe 82 region with both SDSS and UKIDSS data. We find that they can be clearly divided into two classes (quasars and stars) by our criterion in the Y−K versus g−z plot. We select 3834 quasar candidates from the variable sources with g < 20.5 in Stripe 82, 826 of them being SDSS quasars and the rest without SDSS spectroscopy. We estimate the photometric redshifts for 3519 quasar candidates with all UKIDSS YJHK data and find an accuracy of 87.5 per cent within |Δz| < 0.2 with the spectroscopic redshifts of 819 SDSS–UKIDSS identified quasars among them. We demonstrate that even at the same spectroscopy limit as SDSS, with our criterion we can at least partially recover the missing quasars with z∼ 2.7 in SDSS. The SDSS-identified quasars only take a small fraction (21.5 per cent) of our quasar candidates selected from the variable sources in Stripe 82, indicating that deeper spectroscopy is very promising in producing a much larger sample of quasars than SDSS. The implications of our current results for the future Chinese Large Sky Area Multi-Object Fibre Spectroscopic Telescope (LAMOST) quasar survey are also discussed.