Rewrite query to be a bit clearer and not use subselect