Fix constrcuting query to the db when maximumRowsInTable is defined