Attempted SQL query fix