sql: selections when predicate is a select