Refactor SQL statement to prevent table join