reduce unless sql query.