Use an SQL “WHERE NOT EXISTS” subclause.
This is correct performance-wise (avoids the need for the database to build the entire result set before filtering; Django users reported a speed-up of factor 5‥2000 over naïve solutions) and (accepted by Nik) even more legible.
Please register or sign in to comment