use selected fields to check before asking for a column in sql