fixes error in SQL query (invalid column)