Removing maxnum from sql query where there was no such column