Moved the WHERE constraint into the subquery so performance doesn't totally suck